企业微信审批功能跳转外部网页需要的配置(后端)

外部网页需要在初始化后进行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+"&timestamp="+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+"&timestamp="+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;
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值