com.zopen.wechat.mp.service.miniprogram.WechatProgramUserInfoService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zopen-ato-starter Show documentation
Show all versions of zopen-ato-starter Show documentation
Alibaba Tencent And Others For Spring Boot.
package com.zopen.wechat.mp.service.miniprogram;
import com.google.gson.Gson;
import com.zopen.wechat.exception.WechatAssert;
import com.zopen.wechat.mp.dto.miniprogram.MiniProgramPhoneInfo;
import com.zopen.wechat.mp.dto.miniprogram.MiniProgramUserInfo;
import com.zopen.wechat.mp.util.MiniDecryptUtil;
import org.springframework.stereotype.Component;
@Component("atoWechatProgramUserInfoService")
public class WechatProgramUserInfoService {
// 解密获取用户信息
public MiniProgramUserInfo getUserInfo(String encryptedData, String iv, String sessionKey) {
WechatAssert.notNullAndEmpty(encryptedData, "encryptedData 不能为空");
WechatAssert.notNullAndEmpty(sessionKey, "sessionKey 不能为空");
WechatAssert.notNullAndEmpty(iv, "iv 不能为空");
String resultStr = MiniDecryptUtil.decrypt(encryptedData, sessionKey, iv);
WechatAssert.notNullAndEmpty(resultStr, "解密错误");
return new Gson().fromJson(resultStr, MiniProgramUserInfo.class);
}
// 解密获取手机号
public String getPhone(String encryptedData, String iv, String sessionKey) {
WechatAssert.notNullAndEmpty(encryptedData, "encryptedData 不能为空");
WechatAssert.notNullAndEmpty(sessionKey, "sessionKey 不能为空");
WechatAssert.notNullAndEmpty(iv, "iv 不能为空");
String resultStr = MiniDecryptUtil.decrypt(encryptedData, sessionKey, iv);
WechatAssert.notNullAndEmpty(resultStr, "解密错误");
MiniProgramPhoneInfo miniProgramPhoneInfo = new Gson().fromJson(resultStr, MiniProgramPhoneInfo.class);
String result = miniProgramPhoneInfo.getPhoneNumber();
WechatAssert.notNullAndEmpty(result, "手机号获取失败");
return result;
}
}