外部网页需要在初始化后进行wx.config和wx.agentConfig的配置
前端页面需要返回当前的url给后端,根据腾讯的签名算法再组合返回signature
后端代码如下:
public Map test(@RequestParam("url") String url) throws NoSuchAlgorithmException, IOException {
Map<String ,Object> map = new HashMap<String ,Object>();
String corpid = 企业微信id;
String agentid = 应用id;
long timestamp = System.currentTimeMillis() / 1000;
String nonceStr = 随机字符串;
HttpsClient get= new HttpsClient();
String abc=get.sendGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=“+corpid+”&corpsecret=”+corpsecret");
HashMap hashMap = JSON.parseObject(abc, HashMap.class);
String aurl="https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token="+hashMap.get("access_token");
String xyz=get.sendGet(aurl);
HashMap hashMap2 = JSON.parseObject(xyz, HashMap.class);
String temp2 =(String) hashMap2.get("ticket");
String sign2 = "jsapi_ticket="+temp2+"&noncestr="+nonceStr+"×tamp="+timestamp+"&url="+url;
String signature2 = "";
MessageDigest crypt2 = MessageDigest.getInstance("SHA-1");
crypt2.reset();
crypt2.update(sign2.getBytes("UTF-8"));
signature2 = byteToHex(crypt2.digest());
String turl = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token="+hashMap.get("access_token")+"&type=agent_config";
String def=get.sendGet(turl);
HashMap hashMap3 = JSON.parseObject(def, HashMap.class);
String temp =(String) hashMap3.get("ticket");
String sign = "jsapi_ticket="+temp+"&noncestr="+nonceStr+"×tamp="+timestamp+"&url="+url;
String signature = "";
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(sign.getBytes("UTF-8"));
signature = byteToHex(crypt.digest());
map.put("temp", temp);
map.put("url", url);
map.put("signature2", signature2);
map.put("corpid", corpid);
map.put("agentid", agentid);
map.put("timestamp", timestamp);
map.put("nonceStr", nonceStr);
map.put("signature", signature);
return map;
}