From aa0a7a2e1dc2b2aba12d5c014fd0037e30251224 Mon Sep 17 00:00:00 2001 From: wangrenhuang <wangren_huang@163.com> Date: 星期一, 03 四月 2023 16:17:17 +0800 Subject: [PATCH] 新增生成小程序链接方法 --- src/main/java/com/hx/corp/entity/AppLetInfo.java | 22 ++++++++++++++++++++++ src/main/java/com/hx/mp/util/CorpMpUtil.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/corp/entity/AppLetInfo.java b/src/main/java/com/hx/corp/entity/AppLetInfo.java new file mode 100644 index 0000000..ea1780a --- /dev/null +++ b/src/main/java/com/hx/corp/entity/AppLetInfo.java @@ -0,0 +1,22 @@ +package com.hx.corp.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +/** + * @ClassName AppLetInfo + * @Description 鑾峰彇 URL Link 杩斿洖鏁版嵁 + * @Author wrh + * @Date 2023/4/3 16:00 + * @Version 1.0 + */ +@Data +public class AppLetInfo { + //閿欒鐮� + private Integer errcode; + //閿欒淇℃伅 + private String errmsg; + //鐢熸垚鐨勫皬绋嬪簭 URL Link + @JSONField(name="url_link") + private String urlLink; +} diff --git a/src/main/java/com/hx/mp/util/CorpMpUtil.java b/src/main/java/com/hx/mp/util/CorpMpUtil.java index b541e1c..757ee08 100644 --- a/src/main/java/com/hx/mp/util/CorpMpUtil.java +++ b/src/main/java/com/hx/mp/util/CorpMpUtil.java @@ -1,6 +1,8 @@ package com.hx.mp.util; +import com.hx.corp.entity.AppLetInfo; import com.hx.exception.TipsException; +import com.hx.util.HttpMethodUtil; import com.hx.util.StringUtils; import net.sf.json.JSONException; import net.sf.json.JSONObject; @@ -11,6 +13,8 @@ import java.net.HttpURLConnection; import java.net.URL; import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; /** * 浼佷笟寰俊宸ュ叿绫� @@ -39,6 +43,8 @@ public static final String URL_INFO_USER = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={0}&userid={1}"; /**鍙戦�佹秷鎭�*/ public static final String URL_MESSAGE_SEND = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="; + /*鐢熸垚灏忕▼搴忛摼鎺�*/ + public static final String URL_LINK = "https://api.weixin.qq.com/wxa/generate_urllink"; /** * 娣诲姞宸ヤ綔浜哄憳 @@ -339,4 +345,26 @@ } return obj; } + + /** + * 鐢熸垚灏忕▼搴忛摼鎺� + * @param path 閫氳繃 URL Link 杩涘叆鐨勫皬绋嬪簭椤甸潰璺緞锛屽繀椤绘槸宸茬粡鍙戝竷鐨勫皬绋嬪簭瀛樺湪鐨勯〉闈紝涓嶅彲鎼哄甫 query 銆俻ath 涓虹┖鏃朵細璺宠浆灏忕▼搴忎富椤� + * @param token 鎺ュ彛璋冪敤鍑瘉锛岃鍙傛暟涓� URL 鍙傛暟锛岄潪 Body 鍙傛暟銆備娇鐢╣etAccessToken 鎴栬�� + * @param env_version 榛樿鍊�"release"銆傝鎵撳紑鐨勫皬绋嬪簭鐗堟湰銆傛寮忕増涓� "release"锛屼綋楠岀増涓�"trial"锛屽紑鍙戠増涓�"develop"锛屼粎鍦ㄥ井淇″鎵撳紑鏃剁敓鏁堛�� + * @param query 閫氳繃 URL Link 杩涘叆灏忕▼搴忔椂鐨剄uery锛屾渶澶�1024涓瓧绗︼紝鍙敮鎸佹暟瀛楋紝澶у皬鍐欒嫳鏂囦互鍙婇儴鍒嗙壒娈婂瓧绗︼細!#$&'()*+,/:;=?@-._~% + * @return appLetInfo + */ + public static AppLetInfo getAppLetUrl(String path, String token, String env_version, String query) { + Map<String, Object> map = new HashMap(); + map.put("access_token", token); + com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); + data.put("path", path); + data.put("env_version", env_version); + if (!StringUtils.isEmpty(query)){ + data.put("query", query); + } + String datas = HttpMethodUtil.HttpURLUtilJson(URL_LINK, data.toString(), map, (Map)null, "POST"); + AppLetInfo appLetInfo = com.alibaba.fastjson.JSONObject.parseObject(datas, AppLetInfo.class); + return appLetInfo; + } } -- Gitblit v1.8.0