|
@@ -1,5 +1,6 @@
|
|
|
package com.zanxiang.sdk.service.api;
|
|
|
|
|
|
+import com.zanxiang.common.enums.AppletTypeEnum;
|
|
|
import com.zanxiang.common.enums.ExpireTimeEnum;
|
|
|
import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.common.utils.URIUtil;
|
|
@@ -14,6 +15,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author : lingfeng
|
|
@@ -30,6 +32,26 @@ public class WxApiService {
|
|
|
@Autowired
|
|
|
private RedisUtil<String> redisUtil;
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据应用类型获取openId
|
|
|
+ *
|
|
|
+ * @param code : 授权code
|
|
|
+ * @param appId : 应用id
|
|
|
+ * @param secret : 应用密钥
|
|
|
+ * @param type : 应用类型
|
|
|
+ * @return {@link String}
|
|
|
+ */
|
|
|
+ public String getOpenIdByType(String code, String appId, String secret, Integer type) {
|
|
|
+ if (Objects.equals(type, AppletTypeEnum.APPLET_MINI.getType())) {
|
|
|
+ return this.getAppletOpenId(code, appId, secret);
|
|
|
+ }
|
|
|
+ if (Objects.equals(type, AppletTypeEnum.APPLET_MP.getType())) {
|
|
|
+ return this.getMpOpenId(code, appId, secret);
|
|
|
+ }
|
|
|
+ log.error("应用类型不存在, 获取应用openId失败");
|
|
|
+ throw new BaseException("应用类型不存在, 获取应用openId失败");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 小程序/小游戏获取用户应用openId
|
|
|
*
|