64 lines
2.0 KiB
Java
64 lines
2.0 KiB
Java
package com.ruoyi.common.utils;
|
|
|
|
/**
|
|
* @author wangqiong
|
|
* @description 获取微信小程序url scheme
|
|
* @date 2023-10-13 10:16
|
|
*/
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
public class WxAppletNotifyUtils {
|
|
|
|
/**
|
|
* scheme 跳转微信小程序,需中转H5
|
|
|
|
*/
|
|
public static String jumpAppletSchemeUrl(){
|
|
|
|
String token= getAccessToken();
|
|
|
|
//接口地址
|
|
String url = "https://api.weixin.qq.com/wxa/generatescheme?access_token="+token;
|
|
JSONObject body = JSONUtil.createObj();
|
|
JSONObject jumpWxa = JSONUtil.createObj();
|
|
jumpWxa.putOpt("path","pages/login");
|
|
jumpWxa.putOpt("query","");
|
|
jumpWxa.putOpt("env_version","release");
|
|
body.putOpt("jump_wxa",jumpWxa);
|
|
//链接过期类型:0时间戳 1间隔天数
|
|
body.putOpt("expire_type",1);
|
|
body.putOpt("is_expire",true);
|
|
//指定失效天数,最多30
|
|
body.putOpt("expire_interval",30);
|
|
String post = HttpUtil.post(url,body.toJSONString(2));
|
|
JSONObject result = JSONUtil.parseObj(post);
|
|
if(result!=null && result.containsKey("openlink")){
|
|
return result.getStr("openlink");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
//凭证调用
|
|
public static String getAccessToken(){
|
|
String token;
|
|
//小程序APPID
|
|
String appid="wx91cb8459dca561b4";//自行获取
|
|
//小程序secret
|
|
String secret="190aaa3bda96a65d25318fbb0e133fc6";//自己去公众号后台获取
|
|
String httpUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
|
|
|
|
httpUrl= httpUrl+"&appid="+appid+"&secret="+secret;
|
|
//get请求
|
|
String result = HttpUtil.get(httpUrl);
|
|
//解析结果
|
|
JSONObject jsonObject = JSONUtil.parseObj(result);
|
|
//get AccessToken
|
|
token=jsonObject.get("access_token",String.class,false);
|
|
return token;
|
|
}
|
|
|
|
} |