智能仲裁后端服务

WxAppletNotifyUtils.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.ruoyi.common.utils;
  2. /**
  3. * @author wangqiong
  4. * @description 获取微信小程序url scheme
  5. * @date 2023-10-13 10:16
  6. */
  7. import cn.hutool.http.HttpUtil;
  8. import cn.hutool.json.JSONObject;
  9. import cn.hutool.json.JSONUtil;
  10. public class WxAppletNotifyUtils {
  11. /**
  12. * scheme 跳转微信小程序,需中转H5
  13. */
  14. public static String jumpAppletSchemeUrl(){
  15. String token= getAccessToken();
  16. //接口地址
  17. String url = "https://api.weixin.qq.com/wxa/generatescheme?access_token="+token;
  18. JSONObject body = JSONUtil.createObj();
  19. JSONObject jumpWxa = JSONUtil.createObj();
  20. jumpWxa.putOpt("path","pages/login");
  21. jumpWxa.putOpt("query","");
  22. jumpWxa.putOpt("env_version","release");
  23. body.putOpt("jump_wxa",jumpWxa);
  24. //链接过期类型:0时间戳 1间隔天数
  25. body.putOpt("expire_type",1);
  26. body.putOpt("is_expire",true);
  27. //指定失效天数,最多30
  28. body.putOpt("expire_interval",30);
  29. String post = HttpUtil.post(url,body.toJSONString(2));
  30. JSONObject result = JSONUtil.parseObj(post);
  31. if(result!=null && result.containsKey("openlink")){
  32. return result.getStr("openlink");
  33. }
  34. return null;
  35. }
  36. //凭证调用
  37. public static String getAccessToken(){
  38. String token;
  39. //小程序APPID
  40. String appid="wx91cb8459dca561b4";//自行获取
  41. //小程序secret
  42. String secret="190aaa3bda96a65d25318fbb0e133fc6";//自己去公众号后台获取
  43. String httpUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
  44. httpUrl= httpUrl+"&appid="+appid+"&secret="+secret;
  45. //get请求
  46. String result = HttpUtil.get(httpUrl);
  47. //解析结果
  48. JSONObject jsonObject = JSONUtil.parseObj(result);
  49. //get AccessToken
  50. token=jsonObject.get("access_token",String.class,false);
  51. return token;
  52. }
  53. }