All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.wechat.mp.service.miniprogram.WechatProgramUserInfoService Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy