企业微信电脑客户端打开系统默认浏览器

   java    java

企业微信电脑客户端打开系统默认浏览器

JS-SDK

vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
isWeChatOpen() {
const local = location.href.split('#')[0];
const that = this;
makeTicket({url: local}).then((res) => {
if (res.success) {
wx.config({
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: res.data.appId, // 必填,企业微信的corpID
timestamp: res.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
jsApiList: ['openDefaultBrowser', 'closeWindow'] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
});
wx.ready(function () {
const url = that.workwx.author_url + '?appid=' + that.workwx.appid +
'&redirect_uri=' + encodeURIComponent(that.workwx.redirect_uri) +
'&response_type=code&scope=snsapi_privateinfo&agentid=' +
that.workwx.agentid + '&state=STATE#wechat_redirect';
wx.invoke('openDefaultBrowser', {'url': url,}, function (res) {
if (res.err_msg == 'openDefaultBrowser:ok') {
// wx.closeWindow()
// window.close()
}
})
})
} else {
this.$message.warning(res.msg)
}
})
}

java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public static Map<String, Object> getSignature(String url) {
// 企业id
String corpId = "";
// 应用Secret
String secret = "";
// 获取access_token
String getAccessTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
getAccessTokenUrl = String.format(getAccessTokenUrl, corpId, secret);
Map<String, Object> accessTokenMap = HttpClientUtils.get(getAccessTokenUrl);
String token = accessTokenMap.get("access_token").toString();
// 获取企业的jsapi_ticket
String getJsApiTicketUrl = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=%s";
getJsApiTicketUrl = String.format(getJsApiTicketUrl, token);
Map<String, Object> ticketMap = HttpClientUtils.get(getJsApiTicketUrl);
String ticket = ticketMap.get("ticket").toString();
// 获取签名
long timestamp = System.currentTimeMillis() / 1000;
String nonceStr = IdUtil.fastSimpleUUID();
Map<String, Object> params = Maps.newTreeMap();
params.put("jsapi_ticket", ticket);
params.put("noncestr", nonceStr);
params.put("timestamp", timestamp);
params.put("url", url);
String text = params.entrySet().stream()
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining("&"));
String signature = DigestUtils.sha1Hex(text);
return ImmutableMap.of("appId", corpId,
"timestamp", timestamp, "nonceStr", nonceStr, "signature", signature);
}
  1. 企业微信电脑客户端打开系统默认浏览器
    1. JS-SDK
    2. vue
    3. java
缓存算法
mybatis-plus二级缓存