增加获取微信手机号码
This commit is contained in:
parent
e258f2097a
commit
177907dfe6
|
|
@ -1,5 +1,6 @@
|
||||||
package com.mdd.front.controller;
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
import com.mdd.common.utils.ConfigUtil;
|
import com.mdd.common.utils.ConfigUtil;
|
||||||
import com.mdd.front.LikeFrontThreadLocal;
|
import com.mdd.front.LikeFrontThreadLocal;
|
||||||
|
|
@ -61,8 +62,9 @@ public class UserController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/mnpMobile")
|
@PostMapping("/mnpMobile")
|
||||||
public Object mnpMobile(@RequestBody Map<String, String> params) {
|
public Object mnpMobile(@RequestBody Map<String, String> params) {
|
||||||
iUserService.mnpMobile(params);
|
Assert.notNull(params.get("code"), "code参数缺失");
|
||||||
return AjaxResult.success();
|
Map<String, Object> map = iUserService.mnpMobile(params.get("code").trim());
|
||||||
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ public interface IUserService {
|
||||||
*/
|
*/
|
||||||
UserInfoVo info(Integer userId);
|
UserInfoVo info(Integer userId);
|
||||||
|
|
||||||
void mnpMobile(Map<String, String> params);
|
/**
|
||||||
|
* 微信手机
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param code 获取手机号的Code
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
|
Map<String, Object> mnpMobile(String code);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import com.mdd.common.entity.system.SystemConfig;
|
||||||
import com.mdd.common.entity.user.User;
|
import com.mdd.common.entity.user.User;
|
||||||
import com.mdd.common.entity.user.UserAuth;
|
import com.mdd.common.entity.user.UserAuth;
|
||||||
import com.mdd.common.enums.ClientEnum;
|
import com.mdd.common.enums.ClientEnum;
|
||||||
|
import com.mdd.common.exception.OperateException;
|
||||||
import com.mdd.common.mapper.system.SystemConfigMapper;
|
import com.mdd.common.mapper.system.SystemConfigMapper;
|
||||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||||
import com.mdd.common.mapper.user.UserMapper;
|
import com.mdd.common.mapper.user.UserMapper;
|
||||||
|
|
@ -24,6 +25,7 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,9 +106,13 @@ public class UserServiceImpl implements IUserService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信手机号
|
* 微信手机号
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param code 获取手机号的Code
|
||||||
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void mnpMobile(Map<String, String> params) {
|
public Map<String, Object> mnpMobile(String code) {
|
||||||
Map<String, String> config = ConfigUtil.get("mp_channel");
|
Map<String, String> config = ConfigUtil.get("mp_channel");
|
||||||
WxMaService wxMaService = new WxMaServiceImpl();
|
WxMaService wxMaService = new WxMaServiceImpl();
|
||||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||||
|
|
@ -115,17 +121,15 @@ public class UserServiceImpl implements IUserService {
|
||||||
wxMaService.setWxMaConfig(wxConfig);
|
wxMaService.setWxMaConfig(wxConfig);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// String sessionKey = "";
|
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService().getNewPhoneNoInfo(code);
|
||||||
// String encryptedData = params.get("encryptedData");
|
|
||||||
// String ivStr = params.get("iv");
|
|
||||||
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxMaService.getUserService()
|
|
||||||
.getNewPhoneNoInfo("0330FG000I3kwO1Ui81000ZRkr00FG0Y");
|
|
||||||
System.out.println(wxMaPhoneNumberInfo);
|
|
||||||
|
|
||||||
|
Map<String, Object> response = new LinkedHashMap<>();
|
||||||
|
response.put("countryCode", wxMaPhoneNumberInfo.getCountryCode());
|
||||||
|
response.put("phoneNumber", wxMaPhoneNumberInfo.getPhoneNumber());
|
||||||
|
return response;
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
System.out.println(e.getError());
|
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue