|
@@ -44,25 +44,35 @@ public class WeChatService {
|
|
|
private String crmAppId;
|
|
|
@Value("${wx.crm-app-secret}")
|
|
|
private String crmAppSecret;
|
|
|
+ @Value("${wx.hehe-app-id}")
|
|
|
+ private String heHeAppId;
|
|
|
+ @Value("${wx.hehe-app-secret}")
|
|
|
+ private String heHeAppSecret;
|
|
|
|
|
|
public void setRedirectUri(String redirectUri) {
|
|
|
redirectUri = redirectUri;
|
|
|
}
|
|
|
+
|
|
|
public void setAppId(String appId) {
|
|
|
appId = appId;
|
|
|
}
|
|
|
+
|
|
|
public void setAppSecret(String appSecret) {
|
|
|
appSecret = appSecret;
|
|
|
}
|
|
|
+
|
|
|
public void setMiniAppId(String miniAppId) {
|
|
|
miniAppId = miniAppId;
|
|
|
}
|
|
|
+
|
|
|
public void setMiniAppSecret(String miniAppSecret) {
|
|
|
miniAppSecret = miniAppSecret;
|
|
|
}
|
|
|
+
|
|
|
public void setCrmAppId(String crmAppId) {
|
|
|
crmAppId = crmAppId;
|
|
|
}
|
|
|
+
|
|
|
public void setCrmAppSecret(String crmAppSecret) {
|
|
|
crmAppSecret = crmAppSecret;
|
|
|
}
|
|
@@ -70,21 +80,27 @@ public class WeChatService {
|
|
|
public String getRedirectUri() {
|
|
|
return redirectUri;
|
|
|
}
|
|
|
+
|
|
|
public String getAppId() {
|
|
|
return appId;
|
|
|
}
|
|
|
+
|
|
|
public String getAppSecret() {
|
|
|
return appSecret;
|
|
|
}
|
|
|
+
|
|
|
public String getMiniAppId() {
|
|
|
return miniAppId;
|
|
|
}
|
|
|
+
|
|
|
public String getMiniAppSecret() {
|
|
|
return miniAppSecret;
|
|
|
}
|
|
|
+
|
|
|
public String getCrmAppId() {
|
|
|
return crmAppId;
|
|
|
}
|
|
|
+
|
|
|
public String getCrmAppSecret() {
|
|
|
return crmAppSecret;
|
|
|
}
|
|
@@ -99,6 +115,7 @@ public class WeChatService {
|
|
|
// BouncyCastle是一个开源的加解密解决方案
|
|
|
Security.addProvider(new BouncyCastleProvider());
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* AES解密
|
|
|
*
|
|
@@ -136,11 +153,12 @@ public class WeChatService {
|
|
|
/**
|
|
|
* 小程序微信授权登录,获取openid
|
|
|
*
|
|
|
- * @param code 微信凭证
|
|
|
- * @param headers HttpHeaders
|
|
|
+ * @param code 微信凭证
|
|
|
+ * @param headers HttpHeaders
|
|
|
+ * @param mode 1:采美小程序,2:呵呵商城小程序+
|
|
|
* @return HashMap
|
|
|
*/
|
|
|
- public ResponseJson<Map<String, Object>> getInfoMapByApplets(String code, HttpHeaders headers) {
|
|
|
+ public ResponseJson<Map<String, Object>> getInfoMapByApplets(String code, HttpHeaders headers, Integer mode) {
|
|
|
log.info("Start get SessionKey");
|
|
|
Map<String, Object> returnMap = new HashMap<>(4);
|
|
|
// 获取当前微信小程序的环境
|
|
@@ -149,11 +167,19 @@ public class WeChatService {
|
|
|
returnMap.put("referer", referer);
|
|
|
String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
Map<String, String> requestUrlParam = new HashMap<String, String>(4);
|
|
|
- // 小程序appId
|
|
|
- requestUrlParam.put("appid", miniAppId);
|
|
|
- log.info("appId: ---" + miniAppId);
|
|
|
- // 小程序appSecret
|
|
|
- requestUrlParam.put("secret", miniAppSecret);
|
|
|
+ if (mode == 1) {
|
|
|
+ // 小程序appId
|
|
|
+ requestUrlParam.put("appid", miniAppId);
|
|
|
+ log.info("采美小程序appId: ---" + miniAppId);
|
|
|
+ // 小程序appSecret
|
|
|
+ requestUrlParam.put("secret", miniAppSecret);
|
|
|
+ } else {
|
|
|
+ // 呵呵商城小程序appId
|
|
|
+ requestUrlParam.put("appid", heHeAppId);
|
|
|
+ log.info("呵呵商城appId: ---" + heHeAppId);
|
|
|
+ // 呵呵商城小程序appSecret
|
|
|
+ requestUrlParam.put("secret", heHeAppSecret);
|
|
|
+ }
|
|
|
// 小程序端返回的code
|
|
|
requestUrlParam.put("js_code", code);
|
|
|
// 默认参数
|
|
@@ -172,7 +198,7 @@ public class WeChatService {
|
|
|
String sessionKey = jsonObject.getString(Keys.SESSION_KEY);
|
|
|
String errCode = jsonObject.getString("errcode");
|
|
|
String errMsg = jsonObject.getString("errmsg");
|
|
|
- log.info("openId----->" + openId +", unionId------>" + unionId);
|
|
|
+ log.info("openId----->" + openId + ", unionId------>" + unionId);
|
|
|
returnMap.put(Keys.OPEN_ID, openId);
|
|
|
returnMap.put(Keys.UNION_ID, unionId);
|
|
|
returnMap.put(Keys.SESSION_KEY, sessionKey);
|
|
@@ -185,6 +211,7 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 微信公众号授权链接(www)
|
|
|
+ *
|
|
|
* @param redirectUri 用于微信授权的中间页面
|
|
|
* @param mode 授权方式:1静默授权,其他手动同意授权
|
|
|
* @return newRedirectUri
|
|
@@ -204,6 +231,7 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 网页授权登录,通过code获取openid
|
|
|
+ *
|
|
|
* @param code 微信code
|
|
|
* @param source 来源
|
|
|
* @return
|
|
@@ -231,13 +259,14 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 微信公众号获取access_token
|
|
|
+ *
|
|
|
* @return access_token
|
|
|
*/
|
|
|
public String getAccessToken() throws Exception {
|
|
|
String link = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
|
|
|
link = link.replace("APPID", crmAppId);
|
|
|
link = link.replace("APPSECRET", crmAppSecret);
|
|
|
- String result = RequestUtil.sendGet(link);
|
|
|
+ String result = RequestUtil.sendGet(link);
|
|
|
log.info("微信公众号获取access_token>>>" + result);
|
|
|
Map<String, Object> map = JSONObject.parseObject(result, Map.class);
|
|
|
return (String) map.get("access_token");
|
|
@@ -245,6 +274,7 @@ public class WeChatService {
|
|
|
|
|
|
/**
|
|
|
* 微信公众号获取用户信息
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<String, Object> getUserInfo(String accessToken, String openId) throws Exception {
|