微信消息通知动态获取小程序使用的消息模板id 等模板信息

小功能 : 动态获取微信消息模板。 把appid & secret 拿捏一下就可以使用了(getTempId()函数中)


public String getAccess_token(String appid, String appsecret) {
        String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+appsecret;
        JSONObject jsonObject = doGet1(url);
        System.out.println(jsonObject.toString());
        String errCode = jsonObject.getString("expires_in");
        if (!StringUtils.isEmpty(errCode)  && !StringUtils.isEmpty(jsonObject.getString("access_token").toString())) {
            String token = jsonObject.get("access_token").toString();
            return token;
        } else {
            return null;
        }
    }

public List<Map> getTempId(){
        WxUserQueryVo user = wxUserMapper.getWxUserById("用户在本平台的id(本平台用户表中本用户所对应的id号)");
        ///获取appid secret//
        String appid = user.getPlatform();//小程序appid
        BackgroundAppletQueryVo appidinfo = bm.SelectAppId(new BackgroundAppletPageParam().setAppId(appid)); //表中保存了scret appid 等信息 (这里可以通过传参或者什么方式获取appid 与 secret 就行)
        String secret = appidinfo.getScret();
        ///获取appid secret END//
        String acctoken=  getAccess_token(appid,secret);
         
       String url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token="+acctoken;
       HttpGet httpGet = new HttpGet(url);
       String sret = "";
       CloseableHttpClient get = HttpClients.createDefault();
       try{
           Map<String,String> retm = new HashMap<>();
           CloseableHttpResponse execute = get.execute(httpGet);
           if(execute.getStatusLine().getStatusCode()==200){
              HttpEntity httpEntity = execute.getEntity();
               sret +=EntityUtils.toString(httpEntity);
               Map<String,Object> m  = JSON.parseObject(sret);
               List<Map> ol = JSONArray.parseArray(m.get("data").toString(),Map.class);
               //retm.put(m.get("title").toString(),m.get("priTmplId").toString());
               //System.out.println(EntityUtils.toString(httpEntity));
               return ol;
           }
       }catch (Exception e){

       }
        return null;
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值