Commit 915d3a55 authored by muhong's avatar muhong

修改 小程序登录接口

parent 0747b6a3
...@@ -2,7 +2,7 @@ dts: ...@@ -2,7 +2,7 @@ dts:
# 开发者应该设置成自己的wx相关信息 # 开发者应该设置成自己的wx相关信息
wx: wx:
app-id: wx3618eab6c8b144af app-id: wx3618eab6c8b144af
app-secret: 788559035a21b8a75b0c03f9281d5c0a app-secret: 6fee0d7b2197845fed0a3fe8f5a9bd66
mch-id: 1538666666 mch-id: 1538666666
mch-key: 1538xxxxxx-1538xxxxxx-1538xxxxxx mch-key: 1538xxxxxx-1538xxxxxx-1538xxxxxx
notify-url: https://test.dtsshop.com/demo/order/dtsNotify notify-url: https://test.dtsshop.com/demo/order/dtsNotify
...@@ -169,4 +169,6 @@ spring: ...@@ -169,4 +169,6 @@ spring:
server: server:
servlet: servlet:
session: session:
timeout: 720 timeout: 720
\ No newline at end of file
avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc342f573653e38ebd_690x690.png
\ No newline at end of file
...@@ -2,7 +2,7 @@ dts: ...@@ -2,7 +2,7 @@ dts:
# 开发者应该设置成自己的wx相关信息 # 开发者应该设置成自己的wx相关信息
wx: wx:
app-id: wx3618eab6c8b144af app-id: wx3618eab6c8b144af
app-secret: 1a6e073ad84a1a44b6e882f3995bc400 app-secret: 6fee0d7b2197845fed0a3fe8f5a9bd66
mch-id: 1538666666 mch-id: 1538666666
mch-key: 1538xxxxxx-1538xxxxxx-1538xxxxxx mch-key: 1538xxxxxx-1538xxxxxx-1538xxxxxx
notify-url: https://test.dtsshop.com/demo/order/dtsNotify notify-url: https://test.dtsshop.com/demo/order/dtsNotify
...@@ -167,4 +167,6 @@ spring: ...@@ -167,4 +167,6 @@ spring:
server: server:
servlet: servlet:
session: session:
timeout: 720 timeout: 720
\ No newline at end of file
avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc342f573653e38ebd_690x690.png
\ No newline at end of file
package com.wwdz.ch.wx.impl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import com.wwdz.ch.core.util.HttpUtil;
import com.wwdz.ch.wx.service.WxLoginService;
import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class WxLoginServiceImpl implements WxLoginService {
private static final Logger logger = LoggerFactory.getLogger(WxMaServiceImpl.class);
private static final String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/stable_token";
private static final String GET_PHONE_URL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s";
@Value("${dts.wx.app-id}")
private String appid;
@Value("${dts.wx.app-secret}")
private String secret;
@Override
public String getPhone(String code) {
logger.info("开始获取access_token----------------");
Map<String, String> tokenParam = new HashMap<>();
tokenParam.put("grant_type", "client_credential");
tokenParam.put("appid", appid);
tokenParam.put("secret", secret);
String tokenResult = HttpUtil.sendPost(GET_ACCESS_TOKEN_URL, tokenParam);
logger.info("获取access_token的结果是:" + tokenResult);
String accessToken = JsonUtils.getValueByPath(tokenResult, "access_token");
logger.info("开始获取phone-----------------------");
String url = String.format(GET_PHONE_URL, accessToken);
Map<String, String> phoneParam = new HashMap<>();
phoneParam.put("code", code);
String phoneResult = HttpUtil.sendPost(url, phoneParam);
logger.info("获取phone的结果是:" + phoneResult);
return JsonUtils.getValueByPath(phoneResult, "phone_info/phoneNumber");
}
}
package com.wwdz.ch.wx.service;
public interface WxLoginService {
String getPhone(String code);
}
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