Commit 4a8f66da authored by muhong's avatar muhong

修改 小程序登录接口

parent 1f0455ac
...@@ -69,6 +69,9 @@ public class UserServiceImpl implements UserService { ...@@ -69,6 +69,9 @@ public class UserServiceImpl implements UserService {
String mobile = ""; String mobile = "";
try { try {
mobile = wxLoginService.getPhone(dto.getCode()); mobile = wxLoginService.getPhone(dto.getCode());
if (StringUtils.equals("false", mobile)) {
return Result.failed("获取access_token失败");
}
} catch (Exception e) { } catch (Exception e) {
logger.error("获取微信用户手机号失败", e); logger.error("获取微信用户手机号失败", e);
return Result.failed("获取微信用户手机号失败"); return Result.failed("获取微信用户手机号失败");
......
package com.wwdz.ch.wx.impl; package com.wwdz.ch.wx.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import com.wwdz.ch.core.util.HttpUtil; import com.wwdz.ch.core.util.HttpUtil;
import com.wwdz.ch.wx.service.WxLoginService; import com.wwdz.ch.wx.service.WxLoginService;
import com.xxdxxs.utils.JsonUtils; import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -24,17 +26,27 @@ public class WxLoginServiceImpl implements WxLoginService { ...@@ -24,17 +26,27 @@ public class WxLoginServiceImpl implements WxLoginService {
@Value("${dts.wx.app-secret}") @Value("${dts.wx.app-secret}")
private String secret; private String secret;
@Autowired
private WxMaService wxMaService;
@Override @Override
public String getPhone(String code) { public String getPhone(String code) {
logger.info("开始获取access_token----------------"); logger.info("开始获取access_token----------------");
Map<String, String> tokenParam = new HashMap<>(); // Map<String, String> tokenParam = new HashMap<>();
tokenParam.put("grant_type", "client_credential"); // tokenParam.put("grant_type", "client_credential");
tokenParam.put("appid", "wx3618eab6c8b144af"); // tokenParam.put("appid", "wx3618eab6c8b144af");
tokenParam.put("secret", "6fee0d7b2197845fed0a3fe8f5a9bd66"); // tokenParam.put("secret", "6fee0d7b2197845fed0a3fe8f5a9bd66");
String tokenResult = HttpUtil.sendPost(GET_ACCESS_TOKEN_URL, tokenParam); // String tokenResult = HttpUtil.sendPost(GET_ACCESS_TOKEN_URL, tokenParam);
logger.info("获取access_token的结果是:" + tokenResult); // logger.info("获取access_token的结果是:" + tokenResult);
String accessToken = JsonUtils.getValueByPath(tokenResult, "access_token"); // String accessToken = JsonUtils.getValueByPath(tokenResult, "access_token");
String accessToken = "";
try {
accessToken = wxMaService.getAccessToken();
} catch (Exception e) {
logger.error("获取accessToken出错");
return "false";
}
logger.info("开始获取phone-----------------------"); logger.info("开始获取phone-----------------------");
String url = String.format(GET_PHONE_URL, accessToken); String url = String.format(GET_PHONE_URL, accessToken);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment