cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo Java Examples

The following examples show how to use cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WxAuthController.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 微信手机号码绑定
 *
 * @param userId
 * @param body
 * @return
 */
@PostMapping("bindPhone")
public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
	if (userId == null) {
        return ResponseUtil.unlogin();
    }
	LitemallUser user = userService.findById(userId);
    String encryptedData = JacksonUtil.parseString(body, "encryptedData");
    String iv = JacksonUtil.parseString(body, "iv");
    WxMaPhoneNumberInfo phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(user.getSessionKey(), encryptedData, iv);
    String phone = phoneNumberInfo.getPhoneNumber();
    user.setMobile(phone);
    if (userService.updateById(user) == 0) {
        return ResponseUtil.updatedDataFailed();
    }
    return ResponseUtil.ok();
}
 
Example #2
Source File: AppUserController.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
/**
 * 微信用户手机号信息解密
 */
@RequestMapping(value = "wxPhoneDecode", method = {RequestMethod.POST,RequestMethod.GET})
@ApiOperation(notes = "微信用户手机号信息解密", value = "")
@ResponseBody
public Map<String, Object> wxDecode(StockUserSignInVO vo, HttpServletRequest req,
                                    HttpServletResponse res) throws WxErrorException, UnsupportedEncodingException {
    if(com.util.StringUtils.isBlank(vo.getOpenId(),vo.getEncryptedData(),vo.getIvStr())){
        return  ResponseUtil.getNotNormalMap(ResponseMsg.ERROR_PARAM);
    }
    WxMaJscode2SessionResult sessionResult =JSONObject.toJavaObject(JSONObject.parseObject(userCacheUtil.getAppStockUserWxLoginInfo(vo.getOpenId())),WxMaJscode2SessionResult.class);
    WxMaPhoneNumberInfo p =WxMaConfiguration.getWxMaService().getUserService().getPhoneNoInfo(sessionResult.getSessionKey(),vo.getEncryptedData(),vo.getIvStr());
    stockUserService.update(new UpdateWrapper<StockUser>()
            .set("tel",p.getPurePhoneNumber())
            .eq("open_id",vo.getOpenId()));
    return ResponseUtil.getSuccessMap(p);
}
 
Example #3
Source File: WxAuthController.java    From litemall with MIT License 6 votes vote down vote up
/**
 * 微信手机号码绑定
 *
 * @param userId
 * @param body
 * @return
 */
@PostMapping("bindPhone")
public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
	if (userId == null) {
        return ResponseUtil.unlogin();
    }
	LitemallUser user = userService.findById(userId);
    String encryptedData = JacksonUtil.parseString(body, "encryptedData");
    String iv = JacksonUtil.parseString(body, "iv");
    WxMaPhoneNumberInfo phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(user.getSessionKey(), encryptedData, iv);
    String phone = phoneNumberInfo.getPhoneNumber();
    user.setMobile(phone);
    if (userService.updateById(user) == 0) {
        return ResponseUtil.updatedDataFailed();
    }
    return ResponseUtil.ok();
}
 
Example #4
Source File: WxUserController.java    From oneplatform with Apache License 2.0 6 votes vote down vote up
/**
 * <pre>
 * 获取用户绑定手机号信息
 * </pre>
 */
@GetMapping("/phone")
@ApiPermOptions(perms = PermissionType.Logined)
public String phone(@PathVariable String appid, String sessionKey, String signature,
                    String rawData, String encryptedData, String iv) {
    final WxMaService wxService = weixinAppManager.getMaService(appid);

    // 用户信息校验
    if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
        return "user check failed";
    }

    // 解密
    WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);

    return JsonUtils.toJson(phoneNoInfo);
}
 
Example #5
Source File: WxAuthController.java    From dts-shop with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 绑定手机号码
 * 
 * @param userId
 * @param body
 * @return
 */
@PostMapping("bindPhone")
public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
	logger.info("【请求开始】绑定手机号码,请求参数,body:{}", body);

	String sessionKey = UserTokenManager.getSessionKey(userId);
	String encryptedData = JacksonUtil.parseString(body, "encryptedData");
	String iv = JacksonUtil.parseString(body, "iv");
	WxMaPhoneNumberInfo phoneNumberInfo = null;
	try {
		phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
	} catch (Exception e) {
		logger.error("绑定手机号码失败,获取微信绑定的手机号码出错:{}", body);
		e.printStackTrace();
		return ResponseUtil.fail();
	}
	String phone = phoneNumberInfo.getPhoneNumber();
	DtsUser user = userService.findById(userId);
	user.setMobile(phone);
	if (userService.updateById(user) == 0) {
		logger.error("绑定手机号码,更新用户信息出错,id:{}", user.getId());
		return ResponseUtil.updatedDataFailed();
	}
	Map<Object, Object> data = new HashMap<Object, Object>();
	data.put("phone", phone);

	logger.info("【请求结束】绑定手机号码,响应结果:{}", JSONObject.toJSONString(data));
	return ResponseUtil.ok(data);
}
 
Example #6
Source File: WxAuthController.java    From mall with MIT License 5 votes vote down vote up
@PostMapping("bindPhone")
public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
    String sessionKey = UserTokenManager.getSessionKey(userId);
    String encryptedData = JacksonUtil.parseString(body, "encryptedData");
    String iv = JacksonUtil.parseString(body, "iv");
    WxMaPhoneNumberInfo phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
    String phone = phoneNumberInfo.getPhoneNumber();
    LitemallUser user = userService.findById(userId);
    user.setMobile(phone);
    if (userService.updateById(user) == 0) {
        return ResponseUtil.updatedDataFailed();
    }
    return ResponseUtil.ok();
}
 
Example #7
Source File: WxMaUserServiceImplTest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * TODO 测试数据有问题,需要替换为正确的数据
 */
@Test
public void testGetPhoneNoInfo() {
  WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo("tiihtNczf5v6AKRyjwEUhQ==",
    "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew==",
    "r7BXXKkLb8qrSNn05n0qiA==");
  assertNotNull(phoneNoInfo);
  System.out.println(phoneNoInfo.toString());
}
 
Example #8
Source File: WxMaUserController.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 获取用户绑定手机号信息
 * </pre>
 */
@GetMapping("/phone")
public String phone(String sessionKey, String signature, String rawData, String encryptedData, String iv) {
    // 用户信息校验
    if (!this.wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
        return "user check failed";
    }

    // 解密
    WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);

    return JsonUtils.toJson(phoneNoInfo);
}
 
Example #9
Source File: AppUserController.java    From charging_pile_cloud with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    System.out.println(JSONObject.toJSONString(ResponseUtil.getSuccessMap(new WxMaPhoneNumberInfo()), SerializerFeature.WriteMapNullValue));
}
 
Example #10
Source File: WxMaUserServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr) {
  return WxMaPhoneNumberInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr));
}
 
Example #11
Source File: WxMaUser.java    From yue-library with Apache License 2.0 3 votes vote down vote up
/**
    * <pre>
    * 获取用户绑定手机号信息
    * </pre>
    * 
    * @param appid	APPID
    * @param sessionKey 会话密钥
    * @param encryptedData 消息密文
    * @param iv 加密算法的初始向量
    * @return {@linkplain WxMaPhoneNumberInfo} 微信小程序手机号信息
    */
public WxMaPhoneNumberInfo getCellphone(String appid, String sessionKey, String encryptedData, String iv) {
       WxMaService wxService = getMaService(appid);
       
       // 解密
       WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
       
       return wxMaPhoneNumberInfo;
   }
 
Example #12
Source File: WxMaUserService.java    From weixin-java-tools with Apache License 2.0 2 votes vote down vote up
/**
 * 解密用户手机号信息.
 *
 * @param sessionKey    会话密钥
 * @param encryptedData 消息密文
 * @param ivStr         加密算法的初始向量
 */
WxMaPhoneNumberInfo getPhoneNoInfo(String sessionKey, String encryptedData, String ivStr);