支持支付宝获取用户手机号
This commit is contained in:
@@ -111,12 +111,13 @@ public class LoginContoller {
|
||||
// 1.接收小程序发送的code
|
||||
// 2.开发者服务器 登录凭证校验接口 appi + appsecret + code
|
||||
JSONObject wxResp = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete);
|
||||
Integer errCode = wxResp.getInteger("errcode");
|
||||
//Integer errCode = wxResp.getInteger("errcode");
|
||||
log.info("微信获取openid响应报文:{}", wxResp.toJSONString());
|
||||
boolean hasOpenId = wxResp.containsKey("openid");
|
||||
if (!hasOpenId) {
|
||||
return Result.fail("登录失败:" + wxResp.getString("errmsg"));
|
||||
}
|
||||
String a = "{\"width\":\"58\",\"printerNum\":\"1\",\"categoryList\":[{\"id\":30,\"name\":\"奶茶\",\"shortName\":null,\"tree\":null,\"pid\":null,\"pic\":null,\"merchantId\":null,\"shopId\":null,\"style\":null,\"isShow\":null,\"detail\":null,\"sort\":null,\"keyWord\":null,\"createdAt\":null,\"updatedAt\":null},{\"id\":35,\"name\":\"酒水饮料\",\"shortName\":null,\"tree\":null,\"pid\":null,\"pic\":null,\"merchantId\":null,\"shopId\":null,\"style\":null,\"isShow\":null,\"detail\":null,\"sort\":null,\"keyWord\":null,\"createdAt\":null,\"updatedAt\":null},{\"id\":65,\"name\":\"火锅\",\"shortName\":null,\"tree\":null,\"pid\":null,\"pic\":null,\"merchantId\":null,\"shopId\":null,\"style\":null,\"isShow\":null,\"detail\":null,\"sort\":null,\"keyWord\":null,\"createdAt\":null,\"updatedAt\":null},{\"id\":95,\"name\":\"串串\",\"shortName\":null,\"tree\":null,\"pid\":null,\"pic\":null,\"merchantId\":null,\"shopId\":null,\"style\":null,\"isShow\":null,\"detail\":null,\"sort\":null,\"keyWord\":null,\"createdAt\":null,\"updatedAt\":null},{\"id\":96,\"name\":\"烧烤\",\"shortName\":null,\"tree\":null,\"pid\":null,\"pic\":null,\"merchantId\":null,\"shopId\":null,\"style\":null,\"isShow\":null,\"detail\":null,\"sort\":null,\"keyWord\":null,\"createdAt\":null,\"updatedAt\":null}],\"model\":\"normal\",\"feet\":\"0\",\"autoCut\":\"1\"}";
|
||||
// 3.接收微信接口服务 获取返回的参数
|
||||
String openid = wxResp.getString("openid");
|
||||
return loginService.wxCustomLogin(openid, "", "", "", IpUtil.getIpAddr(request));
|
||||
@@ -182,8 +183,23 @@ public class LoginContoller {
|
||||
if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("code") || ObjectUtil.isEmpty(map.get("code"))) {
|
||||
Result.fail("code不能为空");
|
||||
}
|
||||
String code = map.get("code").toString();
|
||||
|
||||
// 三方登录来源 wechat、alipay
|
||||
String source = map.getOrDefault("source",AuthSource.WECHAT.getValue());
|
||||
String code = map.get("code");
|
||||
if (AuthSource.ALIPAY.getValue().equals(source)) {
|
||||
try {
|
||||
String mobile = alipayUtil.getMobile(code);
|
||||
return Result.success(CodeEnum.SUCCESS, mobile);
|
||||
}catch (AlipayApiException e){
|
||||
log.error("获取手机号失败:",e);
|
||||
return Result.fail("获取手机号失败:"+e.getErrMsg());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("登录手机号失败:",e);
|
||||
return Result.fail("获取手机号失败:未知错误");
|
||||
}
|
||||
}
|
||||
String encryptedData = map.get("encryptedData");
|
||||
|
||||
String ivStr = map.get("iv");
|
||||
|
||||
Reference in New Issue
Block a user