package com.liquidnet.service.adam.service;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.liquidnet.service.adam.config.WechatMaConfigure;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdamWechatService {
    @Autowired
    WechatMaConfigure wechatMaConfigure;

    public WxMaJscode2SessionResult sessionInfo(String code, Integer anum) throws WxErrorException {
        WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
        return wxMaService.getUserService().getSessionInfo(code);
    }

    public WxMaUserInfo userInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
        WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
        return wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
    }

    public WxMaPhoneNumberInfo phoneNumberInfo(String sessionKey, String encryptedData, String iv, Integer anum) {
        WxMaService wxMaService = wechatMaConfigure.getWxMaService(anum);
        return wxMaService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
    }
}
