|
@@ -1,5 +1,6 @@
|
|
|
package com.miaxis.app.controller.user;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.miaxis.common.core.controller.BaseController;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
@@ -34,8 +35,8 @@ import java.util.Map;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/user/info")
|
|
|
-@Api(tags={"【app-用户】"})
|
|
|
-public class UserInfoController extends BaseController{
|
|
|
+@Api(tags = {"【app-用户】"})
|
|
|
+public class UserInfoController extends BaseController {
|
|
|
@Autowired
|
|
|
private IUserInfoService userInfoService;
|
|
|
|
|
@@ -46,7 +47,7 @@ public class UserInfoController extends BaseController{
|
|
|
private IWxService wxService;
|
|
|
|
|
|
|
|
|
- private String rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMLNHTgsyYOXDJVF8r4qCyb+8Uw4" +
|
|
|
+ private String rsaPrivateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMLNHTgsyYOXDJVF8r4qCyb+8Uw4" +
|
|
|
"XKq8aThAhUIaPYIop+HJxETGbXk3e0o46i4iOX8RTv0i3jmhL6W0mSxy9ismfXPP7VtKgEt6VnMm" +
|
|
|
"ufsrQ2kcXyRsKmuwUd3rTH5gniXwLdIPF8V5ujiSq94nPHok1krDMWbss8Q7lcH2kQFHAgMBAAEC" +
|
|
|
"gYBh6Eu2TzRdMg79+7EciO8gA2Tt5SoWGipcPnl7lsqxX5O5dPpzgrPFB/CshlyVIVh6mA12Rw8g" +
|
|
@@ -75,7 +76,7 @@ public class UserInfoController extends BaseController{
|
|
|
userVipInfoVO.setUnionId(dbUserInfo.getUnionId());
|
|
|
userVipInfoVO.setHeadImage(dbUserInfo.getHeadImage());
|
|
|
userVipInfoVO.setNickName(dbUserInfo.getNickName());
|
|
|
- userVipInfoVO.setSign(getSign(dbUserInfo.getIsVip(),dbUserInfo.getUnionId()));
|
|
|
+ userVipInfoVO.setSign(getSign(dbUserInfo.getIsVip(), dbUserInfo.getUnionId()));
|
|
|
return Response.success(userVipInfoVO);
|
|
|
}
|
|
|
|
|
@@ -84,44 +85,56 @@ public class UserInfoController extends BaseController{
|
|
|
*/
|
|
|
@PutMapping(value = "/userInfo")
|
|
|
@ApiOperation("更新昵称、手机号码、头像")
|
|
|
- public Response updateInfo(String nickName,String phone,String headImage) {
|
|
|
+ public Response updateInfo(String nickName, String phone, String headImage) {
|
|
|
Long id = SecurityUtils.getLoginUser().getStudent().getId();
|
|
|
UserInfo dbUserInfo = userInfoService.getById(id);
|
|
|
dbUserInfo.setNickName(nickName);
|
|
|
dbUserInfo.setPhone(phone);
|
|
|
- if(!StringUtils.isEmpty(headImage)) {
|
|
|
+ if (!StringUtils.isEmpty(headImage)) {
|
|
|
dbUserInfo.setHeadImage(headImage);
|
|
|
}
|
|
|
return Response.success(userInfoService.updateById(dbUserInfo));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //根据code获取手机号
|
|
|
+ /**
|
|
|
+ * 根据code获取手机号
|
|
|
+ *
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@GetMapping(value = "/getPhoneByCode")
|
|
|
@ApiOperation("根据code获取手机号")
|
|
|
- public Response getPhoneByCode(String code) {
|
|
|
+ public Response getPhoneByCode(String code) {
|
|
|
String accsesToken = wxLocalService.getLocalXcxToken();
|
|
|
WxGetPhoneDTO wxGetPhoneDTO = new WxGetPhoneDTO();
|
|
|
wxGetPhoneDTO.setCode(code);
|
|
|
- String phoneNumber = wxService.getUserPhoneNumber(accsesToken,wxGetPhoneDTO);
|
|
|
- return Response.success(phoneNumber);
|
|
|
- }
|
|
|
+ String resultStr = wxService.getUserPhoneNumber(accsesToken, wxGetPhoneDTO);
|
|
|
+ JSONObject resultData = JSONObject.parseObject(resultStr);
|
|
|
+
|
|
|
+ String errcode = resultData.getString("errcode");
|
|
|
+ if("0".equals(errcode)) {
|
|
|
+ JSONObject phoneInfo = resultData.getJSONObject("phone_info");
|
|
|
+ String purePhoneNumber = phoneInfo.getString("purePhoneNumber");
|
|
|
+ return Response.success(purePhoneNumber);
|
|
|
+ } else {
|
|
|
+ return Response.success(resultStr);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- private String getSign(Integer isVip, String unionId) throws Exception {
|
|
|
- String str = unionId+isVip;
|
|
|
+ private String getSign(Integer isVip, String unionId) throws Exception {
|
|
|
+ String str = unionId + isVip;
|
|
|
// 进行签名服务
|
|
|
Signature signature = Signature.getInstance("SHA256withRSA");
|
|
|
KeyFactory kf = KeyFactory.getInstance("RSA");
|
|
|
- PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey)));
|
|
|
+ PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey)));
|
|
|
signature.initSign(privateKey);
|
|
|
signature.update(str.getBytes("UTF-8"));
|
|
|
byte[] signedData = signature.sign();
|
|
|
return Base64.getEncoder().encodeToString(signedData);
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|