Ver código fonte

微信授权登录

chunping 3 anos atrás
pai
commit
74e958ca1f

+ 6 - 5
mp-admin/src/main/java/com/qs/mp/web/controller/api/common/UserController.java

@@ -168,7 +168,7 @@ public class UserController extends BaseApiController {
       appSecret = channelAppSecret;
     }
     //调用微信后台接口获取openId
-    String res = getWxMobile(wxLoginParams, appId, appSecret);
+    String res = getWxMobile(wxLoginParams, appId);
     JSONObject jsonObject = JSONObject.parseObject(res);
     int errcode = jsonObject.getIntValue("errcode");
     if (errcode != 0 ) {
@@ -275,11 +275,12 @@ public class UserController extends BaseApiController {
    * @param
    * @return
    */
-  private String getWxMobile(WxLoginParams params, String appId, String appSecret) {
+  private String getWxMobile(WxLoginParams params, String appId) {
     String accessToken = appTokenService.getAccessToken(appId);
-    String param = "code=" + params.getCode();
-    LogUtil.info(logger, param);
-    String res = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken, param);
+    JSONObject jsonObject = new JSONObject();
+    jsonObject.put("code", params.getCode());
+    LogUtil.info(logger, JSONObject.toJSONString(params));
+    String res = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + accessToken, jsonObject.toJSONString());
     return res;
   }