|
@@ -27,14 +27,20 @@ public class WeChatUtil {
|
|
|
@Value("${xjrsoft.enterpriseWeChat.agentid}")
|
|
|
public Integer agentid;
|
|
|
|
|
|
- @Value("${xjrsoft.mpWeixin.appKey}")
|
|
|
+ @Value("${xjrsoft.mpWeChat.appKey}")
|
|
|
public String mpAppKey;
|
|
|
|
|
|
- @Value("${xjrsoft.mpWeixin.appSecret}")
|
|
|
+ @Value("${xjrsoft.mpWeChat.appSecret}")
|
|
|
public String mpAppSecret;
|
|
|
|
|
|
- //获取Openid
|
|
|
- public String getOpenid(String code) {
|
|
|
+ @Value("${xjrsoft.appletWeChat.appKey}")
|
|
|
+ public String appletAppKey;
|
|
|
+
|
|
|
+ @Value("${xjrsoft.appletWeChat.appSecret}")
|
|
|
+ public String appletAppSecret;
|
|
|
+
|
|
|
+ //公众号获取Openid
|
|
|
+ public String[] getMpOpenid(String code) {
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
paramMap.put("appid", mpAppKey);
|
|
|
paramMap.put("secret", mpAppSecret);
|
|
@@ -47,7 +53,30 @@ public class WeChatUtil {
|
|
|
return null;
|
|
|
}
|
|
|
String openId = jsonObject.get("openid").toString();
|
|
|
- return openId;
|
|
|
+ String[] arrayRefVar = { openId,""};
|
|
|
+ return arrayRefVar;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小程序
|
|
|
+ public String[] getOpenid(String code) {
|
|
|
+ HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("appid", appletAppKey);
|
|
|
+ paramMap.put("secret", appletAppSecret);
|
|
|
+ paramMap.put("js_code", code);
|
|
|
+ paramMap.put("grant_type", "authorization_code");
|
|
|
+ String result = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session", paramMap);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if (jsonObject.containsKey("errcode")) {
|
|
|
+ //throw new MyException(result);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String openId = jsonObject.get("openid").toString();
|
|
|
+ String unionid = "";
|
|
|
+ if (jsonObject.containsKey("unionid")) {
|
|
|
+ unionid = jsonObject.get("unionid").toString();
|
|
|
+ }
|
|
|
+ String[] arrayRefVar = {openId, unionid};
|
|
|
+ return arrayRefVar;
|
|
|
}
|
|
|
|
|
|
//获取通讯录或发消息token
|