package com.xunhong.erp.turbo.facade.app.executor.query;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.xunhong.erp.turbo.api.facade.dto.qry.WxMaOpenidQry;
import com.xunhong.erp.turbo.api.facade.dto.vo.WxMaOpenidVO;
import com.xunhong.erp.turbo.api.infra.api.SettingServiceI;
import com.xunhong.erp.turbo.facade.app.executor.common.WxCmdExe;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @author shenyifei
 */
@Component
@RequiredArgsConstructor
public class WxOpenidQryExe extends WxCmdExe {

	@DubboReference(version = "1.0.0")
	private final SettingServiceI settingService;

	@SneakyThrows
	public WxMaOpenidVO execute(WxMaOpenidQry wxMaOpenidQry) {
		WxMaService wxMaService = getWxMaService(settingService);
		WxMaJscode2SessionResult wxMaJscode2SessionResult = wxMaService.jsCode2SessionInfo(wxMaOpenidQry.getCode());

		WxMaOpenidVO wxMaOpenidVO = new WxMaOpenidVO();
		wxMaOpenidVO.setOpenid(wxMaJscode2SessionResult.getOpenid());
		wxMaOpenidVO.setUnionid(wxMaJscode2SessionResult.getUnionid());
		return wxMaOpenidVO;
	}
}
