|
@@ -1,16 +1,14 @@
|
|
|
package com.care.client.service;
|
|
|
|
|
|
-import cn.hutool.http.HttpRequest;
|
|
|
-import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
+
|
|
|
import com.care.client.config.PlatformPinanbaoConfig;
|
|
|
import com.care.client.config.WxConfig;
|
|
|
import com.care.client.vo.MemberInitParams;
|
|
|
import com.care.common.cache.RedisKeyConstant;
|
|
|
import com.care.common.cache.RedisUtil;
|
|
|
+import com.care.common.util.HttpUtil;
|
|
|
import com.care.common.util.Result;
|
|
|
-import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -27,14 +25,13 @@ public class WxPassportService extends AbstractPassportService {
|
|
|
@Resource
|
|
|
private PlatformPinanbaoConfig platformPinanbaoConfig;
|
|
|
|
|
|
- Gson gson = new Gson();
|
|
|
|
|
|
public Result<Object> login(MemberInitParams params) {
|
|
|
WxConfig wxConfig = platformPinanbaoConfig.wxConfig();
|
|
|
// 解析codeUrl
|
|
|
String codeUrl = MessageFormat.format(wxConfig.getCodeUrl(), wxConfig.getAppId(), wxConfig.getSecret(), params.getCode());
|
|
|
// 通过codeUrl获取openid
|
|
|
- JSONObject jsonObject = this.httpGet(codeUrl);
|
|
|
+ JSONObject jsonObject = HttpUtil.httpGet(codeUrl);
|
|
|
log.warn("-----jsonObject:[{}]", jsonObject);
|
|
|
|
|
|
String openid = jsonObject.getStr("openid");
|
|
@@ -50,14 +47,7 @@ public class WxPassportService extends AbstractPassportService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private JSONObject httpGet(String url) {
|
|
|
- HttpResponse response = HttpRequest.get(url).execute();
|
|
|
- String json = response.charset("utf-8").body();
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(json);
|
|
|
- return jsonObject;
|
|
|
- }
|
|
|
-
|
|
|
- private String accessToken() {
|
|
|
+ public String accessToken() {
|
|
|
WxConfig wxConfig = platformPinanbaoConfig.wxConfig();
|
|
|
String access_token = (String) redisUtil.hget(RedisKeyConstant.WX_ACCESS_TOKEN, wxConfig.getAppId());
|
|
|
if (access_token != null) {
|
|
@@ -71,7 +61,7 @@ public class WxPassportService extends AbstractPassportService {
|
|
|
// 解析codeUrl
|
|
|
String tokenUrl = MessageFormat.format(wxConfig.getTokenUrl(), wxConfig.getAppId(), wxConfig.getSecret());
|
|
|
// 通过codeUrl获取openid
|
|
|
- JSONObject jsonObject = this.httpGet(tokenUrl);
|
|
|
+ JSONObject jsonObject = HttpUtil.httpGet(tokenUrl);
|
|
|
String access_token = jsonObject.getStr("access_token");
|
|
|
redisUtil.hset(RedisKeyConstant.WX_ACCESS_TOKEN, wxConfig.getAppId(), access_token, RedisKeyConstant.WX_ACCESS_TOKEN_TIME);
|
|
|
return access_token;
|