package com.bonus.canteen.core.common.thirdutils.alipay;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.*;
import com.alipay.api.domain.*;
import com.alipay.api.internal.util.AlipayEncrypt;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.canteen.core.allocation.api.AllocPayMetadataApi;
import com.bonus.canteen.core.allocation.api.GlobalMetadataApi;
import com.bonus.canteen.core.allocation.mobile.model.EnterpriseCodeMetadataModel;
import com.bonus.canteen.core.auth.mobile.alipay.dto.AliPayApplyAuditDTO;
import com.bonus.canteen.core.auth.mobile.alipay.dto.AliPayUserAgreementQueryDTO;
import com.bonus.canteen.core.common.config.sys.ThirdApiUrlProperties;
import com.bonus.canteen.core.common.enums.MetadataModelTypeEnum;
import com.bonus.canteen.core.common.thirdutils.alipay.model.AlipayProperties;
import com.bonus.canteen.core.common.thirdutils.alipay.model.AlipayReq;
import com.bonus.canteen.core.common.utils.TenantContextHolder;
import com.bonus.canteen.core.device.manage.controller.deprecated.dto.MachineGetAuthTokenDTO;
import com.bonus.canteen.core.menuai.utils.MenuaiUtils;
import com.bonus.canteen.core.pay.common.dto.PayParamDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class AliPayUtil {
   private static final Logger log = LoggerFactory.getLogger(AliPayUtil.class);
   @Resource
   private AlipayProperties alipayProperties;
   @Resource
   private ThirdApiUrlProperties thirdApiUrlProperties;
   @Resource
   private AllocPayMetadataApi allocPayMetadataApi;
   @Resource
   private GlobalMetadataApi globalMetadataApi;
   private static final String personalProductCode = "GENERAL_WITHHOLDING_P";
   private static final String signScene = "INDUSTRY|CATERING";

   public AlipaySystemOauthTokenResponse getAuthToken(String authCode, AlipayReq alipayReq) {
      AlipaySystemOauthTokenRequest alipaySystemOauthTokenRequest = new AlipaySystemOauthTokenRequest();
      alipaySystemOauthTokenRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      alipaySystemOauthTokenRequest.setCode(authCode);
      alipaySystemOauthTokenRequest.setGrantType("authorization_code");
      log.info("换取授权访问令牌请求参数:{}", JSON.toJSONString(alipaySystemOauthTokenRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipaySystemOauthTokenResponse response = (AlipaySystemOauthTokenResponse)alipayClient.execute(alipaySystemOauthTokenRequest);
         log.info("换取授权访问令牌响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("用户授权失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("用户授权失败");
         }
      } catch (AlipayApiException var6) {
         throw new ServiceException("换取授权访问令牌异常");
      }
   }

   public String getUserInfo(String authToken, AlipayReq alipayReq) {
      AlipayUserInfoShareRequest alipayUserInfoShareRequest = new AlipayUserInfoShareRequest();
      alipayUserInfoShareRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      log.info("支付宝会员授权信息请求参数:{}", JSON.toJSONString(alipayUserInfoShareRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayUserInfoShareResponse response = (AlipayUserInfoShareResponse)alipayClient.execute(alipayUserInfoShareRequest, authToken);
         log.info("支付宝会员授权信息响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response.getNickName();
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝会员授权信息失败，原因：" + var10001 + "，" + response.getSubMsg());
            return null;
         }
      } catch (AlipayApiException var6) {
         log.info("支付宝会员授权信息异常：" + var6.getMessage());
         return null;
      }
   }

   public String userAgreementPageSign(AlipayReq alipayReq) {
      AlipayUserAgreementPageSignRequest alipayUserAgreementPageSignRequest = new AlipayUserAgreementPageSignRequest();
      alipayUserAgreementPageSignRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      AlipayUserAgreementPageSignModel model = new AlipayUserAgreementPageSignModel();
      model.setExternalLogonId(String.valueOf(TenantContextHolder.getTenantId()));
      model.setProductCode("GENERAL_WITHHOLDING");
      model.setPersonalProductCode("GENERAL_WITHHOLDING_P");
      model.setSignScene("INDUSTRY|CATERING");
      AccessParams accessParams = new AccessParams();
      accessParams.setChannel("ALIPAYAPP");
      model.setAccessParams(accessParams);
      alipayUserAgreementPageSignRequest.setBizModel(model);
      alipayUserAgreementPageSignRequest.setNotifyUrl(alipayReq.getAlipayNotifyUrl() + "/tengyun-api/api/v1/applet/alipay/notify");
      log.info("签约代扣协议请求参数:{}", JSON.toJSONString(alipayUserAgreementPageSignRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayUserAgreementPageSignResponse response = (AlipayUserAgreementPageSignResponse)alipayClient.sdkExecute(alipayUserAgreementPageSignRequest);
         log.info("签约代扣协议响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response.getBody();
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("签约代扣协议失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("签约代扣协议失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("签约代扣协议异常");
      }
   }

   public AlipayUserAgreementQueryResponse userAgreementQuery(AliPayUserAgreementQueryDTO aliPayUserAgreementQueryDTO, AlipayReq alipayReq) {
      AlipayUserAgreementQueryRequest alipayUserAgreementQueryRequest = new AlipayUserAgreementQueryRequest();
      alipayUserAgreementQueryRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      AlipayUserAgreementQueryModel model = new AlipayUserAgreementQueryModel();
      if (StringUtils.isNotBlank(aliPayUserAgreementQueryDTO.getAgreementNo())) {
         model.setAgreementNo(aliPayUserAgreementQueryDTO.getAgreementNo());
      } else {
         model.setPersonalProductCode("GENERAL_WITHHOLDING_P");
         model.setSignScene("INDUSTRY|CATERING");
         model.setAlipayUserId(aliPayUserAgreementQueryDTO.getAlipayUserId());
      }

      alipayUserAgreementQueryRequest.setBizModel(model);
      log.info("查询代扣协议请求参数:{}", JSON.toJSONString(alipayUserAgreementQueryRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayUserAgreementQueryResponse response = (AlipayUserAgreementQueryResponse)alipayClient.execute(alipayUserAgreementQueryRequest);
         log.info("查询代扣协议响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("查询代扣协议失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("查询代扣协议失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("查询代扣协议异常");
      }
   }

   public String customerSmilepayInitialize(MachineGetAuthTokenDTO machineGetAuthTokenDTO, AlipayReq alipayReq) {
      ZolozAuthenticationCustomerSmilepayInitializeRequest initializeRequest = new ZolozAuthenticationCustomerSmilepayInitializeRequest();
      initializeRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      ZolozAuthenticationCustomerSmilepayInitializeModel model = new ZolozAuthenticationCustomerSmilepayInitializeModel();
      model.setServiceId(machineGetAuthTokenDTO.getServiceId());
      model.setZimmetainfo(machineGetAuthTokenDTO.getMetaInfo());
      JSONObject serviceParams = new JSONObject();
      serviceParams.put("authCheck", "true");
      model.setServiceParams(serviceParams.toJSONString());
      initializeRequest.setBizModel(model);
      log.info("人脸刷脸付初始化请求参数:{}", JSON.toJSONString(initializeRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         ZolozAuthenticationCustomerSmilepayInitializeResponse response = (ZolozAuthenticationCustomerSmilepayInitializeResponse)alipayClient.execute(initializeRequest);
         log.info("人脸刷脸付初始化响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            JSONObject result = JSON.parseObject(response.getResult());
            String authToken = result.getString("authToken");
            log.info("获取设备authToken：{}", authToken);
            return authToken;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("人脸刷脸付初始化失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("人脸刷脸付初始化失败");
         }
      } catch (AlipayApiException var10) {
         throw new ServiceException("人脸刷脸付初始化异常");
      }
   }

   public String paymentCodeDecod(String authCode, AlipayReq alipayReq) {
      AlipayUserTwostageCommonUseRequest alipayUserTwostageCommonUseRequest = new AlipayUserTwostageCommonUseRequest();
      alipayUserTwostageCommonUseRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      AlipayUserTwostageCommonUseModel model = new AlipayUserTwostageCommonUseModel();
      model.setDynamicId(authCode);
      model.setSenceNo(authCode);
      model.setPayCheckStrategy("1");
      model.setPayPid(this.allocPayMetadataApi.queryAvailablePayModel((Long)null).getAlipayMerPid());
      alipayUserTwostageCommonUseRequest.setBizModel(model);
      log.info("支付宝付款码解码请求参数:{}", JSON.toJSONString(alipayUserTwostageCommonUseRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayUserTwostageCommonUseResponse response = (AlipayUserTwostageCommonUseResponse)alipayClient.execute(alipayUserTwostageCommonUseRequest);
         log.info("支付宝付款码解码响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response.getUserId();
         } else if ("USER_UN_AUTH".equals(response.getSubCode())) {
            return null;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝付款码解码失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝付款码解码失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝付款码解码异常");
      }
   }

   public String decode(String authCode, String appAuthToken) {
      AlipayUserTwostageCommonUseRequest alipayUserTwostageCommonUseRequest = new AlipayUserTwostageCommonUseRequest();
      alipayUserTwostageCommonUseRequest.putOtherTextParam("app_auth_token", appAuthToken);
      AlipayUserTwostageCommonUseModel model = new AlipayUserTwostageCommonUseModel();
      model.setDynamicId(authCode);
      model.setSenceNo(authCode);
      model.setPayPid(this.allocPayMetadataApi.queryAvailablePayModel(TenantContextHolder.getTenantId()).getAlipayMerPid());
      alipayUserTwostageCommonUseRequest.setBizModel(model);
      log.info("支付宝付款码解码请求参数:{}", JSON.toJSONString(alipayUserTwostageCommonUseRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getEnterpriseClientParams());
         AlipayUserTwostageCommonUseResponse response = (AlipayUserTwostageCommonUseResponse)alipayClient.execute(alipayUserTwostageCommonUseRequest);
         log.info("支付宝付款码解码响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response.getUserId();
         } else if ("USER_UN_AUTH".equals(response.getSubCode())) {
            return null;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝付款码解码失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝付款码解码失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝付款码解码异常");
      }
   }

   public AlipayConfig getEnterpriseClientParams() {
      AlipayConfig certParams = new AlipayConfig();
      certParams.setServerUrl(this.thirdApiUrlProperties.getApialipay());
      certParams.setAppId(((EnterpriseCodeMetadataModel)this.globalMetadataApi.getModel(MetadataModelTypeEnum.ENTERPRISE_CODE, new EnterpriseCodeMetadataModel(), (Long)null, (Long)null)).getAliPayEnterpriseAppId());
      certParams.setPrivateKey(this.alipayProperties.getAlipayAppPrikey());
      certParams.setAlipayPublicKey(this.alipayProperties.getAlipayPublicKey());
      return certParams;
   }

   public AlipayTradePayResponse alipayTradePay(PayParamDTO payParam, AlipayReq alipayReq) {
      AlipayTradePayRequest alipayTradePayRequest = new AlipayTradePayRequest();
      alipayTradePayRequest.putOtherTextParam("app_auth_token", alipayReq.getAlipayAppAuthToken());
      AlipayTradePayModel payModel = new AlipayTradePayModel();
      payModel.setOutTradeNo(String.valueOf(payParam.getTradeId()));
      payModel.setTotalAmount("0.01");
      payModel.setSubject("乐牛智慧餐厅");
      payModel.setProductCode("GENERAL_WITHHOLDING");
      AgreementParams agreementParams = new AgreementParams();
      agreementParams.setAgreementNo("20225504849374413667");
      payModel.setAgreementParams(agreementParams);
      alipayTradePayRequest.setBizModel(payModel);
      log.info("支付宝同步代扣请求参数:{}", JSON.toJSONString(alipayTradePayRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayTradePayResponse response = (AlipayTradePayResponse)alipayClient.execute(alipayTradePayRequest);
         log.info("支付宝同步代扣响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝同步代扣失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝同步代扣失败");
         }
      } catch (AlipayApiException var8) {
         throw new ServiceException("支付宝同步代扣异常");
      }
   }

   public List<String> queryVersionList(String alipayAppAuthToken) {
      AlipayOpenMiniVersionListQueryRequest alipayOpenMiniVersionListQueryRequest = new AlipayOpenMiniVersionListQueryRequest();
      alipayOpenMiniVersionListQueryRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      log.info("支付宝小程序版本列表查询请求参数:{}", JSON.toJSONString(alipayOpenMiniVersionListQueryRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniVersionListQueryResponse response = (AlipayOpenMiniVersionListQueryResponse)alipayClient.execute(alipayOpenMiniVersionListQueryRequest);
         log.info("支付宝小程序版本列表查询响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response.getAppVersions();
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序版本列表查询失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序版本列表查询失败");
         }
      } catch (AlipayApiException var5) {
         throw new ServiceException("支付宝小程序版本列表查询异常");
      }
   }

   public AlipayOpenMiniVersionDetailQueryResponse queryVersionDetail(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniVersionDetailQueryRequest alipayOpenMiniVersionDetailQueryRequest = new AlipayOpenMiniVersionDetailQueryRequest();
      alipayOpenMiniVersionDetailQueryRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniVersionDetailQueryModel model = new AlipayOpenMiniVersionDetailQueryModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniVersionDetailQueryRequest.setBizModel(model);
      log.info("支付宝小程序版本详情查询请求参数:{}", JSON.toJSONString(alipayOpenMiniVersionDetailQueryRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniVersionDetailQueryResponse response = (AlipayOpenMiniVersionDetailQueryResponse)alipayClient.execute(alipayOpenMiniVersionDetailQueryRequest);
         log.info("支付宝小程序版本详情查询响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序版本详情查询失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序版本详情查询失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序版本详情查询异常");
      }
   }

   public Boolean uploadAppVersion(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniExperienceCreateRequest alipayOpenMiniExperienceCreateRequest = new AlipayOpenMiniExperienceCreateRequest();
      alipayOpenMiniExperienceCreateRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniExperienceCreateModel model = new AlipayOpenMiniExperienceCreateModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniExperienceCreateRequest.setBizModel(model);
      log.info("支付宝小程序生成体验版请求参数:{}", JSON.toJSONString(alipayOpenMiniExperienceCreateRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniExperienceCreateResponse response = (AlipayOpenMiniExperienceCreateResponse)alipayClient.execute(alipayOpenMiniExperienceCreateRequest);
         log.info("支付宝小程序生成体验版响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return true;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序生成体验版失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序生成体验版失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序生成体验版异常");
      }
   }

   public AlipayOpenMiniExperienceQueryResponse queryAppVersion(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniExperienceQueryRequest alipayOpenMiniExperienceQueryRequest = new AlipayOpenMiniExperienceQueryRequest();
      alipayOpenMiniExperienceQueryRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniExperienceQueryModel model = new AlipayOpenMiniExperienceQueryModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniExperienceQueryRequest.setBizModel(model);
      log.info("支付宝小程序体验版状态查询请求参数:{}", JSON.toJSONString(alipayOpenMiniExperienceQueryRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniExperienceQueryResponse response = (AlipayOpenMiniExperienceQueryResponse)alipayClient.execute(alipayOpenMiniExperienceQueryRequest);
         log.info("支付宝小程序体验版状态查询响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            return response;
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序体验版状态查询失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序体验版状态查询失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序体验版状态查询异常");
      }
   }

   public void cancelExperience(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniExperienceCancelRequest alipayOpenMiniExperienceCancelRequest = new AlipayOpenMiniExperienceCancelRequest();
      alipayOpenMiniExperienceCancelRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniExperienceCancelModel model = new AlipayOpenMiniExperienceCancelModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniExperienceCancelRequest.setBizModel(model);
      log.info("支付宝小程序取消体验版请求参数:{}", JSON.toJSONString(alipayOpenMiniExperienceCancelRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniExperienceCancelResponse response = (AlipayOpenMiniExperienceCancelResponse)alipayClient.execute(alipayOpenMiniExperienceCancelRequest);
         log.info("支付宝小程序取消体验版响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            log.info("支付宝小程序取消体验版成功");
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序取消体验版失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序取消体验版失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序取消体验版异常");
      }
   }

   public void applyAudit(AliPayApplyAuditDTO aliPayApplyAuditDTO) {
      AlipayOpenMiniVersionAuditApplyRequest request = new AlipayOpenMiniVersionAuditApplyRequest();
      request.putOtherTextParam("app_auth_token", aliPayApplyAuditDTO.getAlipayAppAuthToken());
      request.setVersionDesc(aliPayApplyAuditDTO.getVersionDesc());
      request.setRegionType("GLOBAL");
      request.setServiceRegionInfo(new ArrayList());
      request.setAppVersion(aliPayApplyAuditDTO.getAppVersion());
      request.setServicePhone(aliPayApplyAuditDTO.getServicePhone());
      request.setAutoOnline("true");
      request.setMemo(aliPayApplyAuditDTO.getMemo());

      try {
         request.setFifthScreenShot(new FileItem(MenuaiUtils.getFile(aliPayApplyAuditDTO.getFirstScreenShot())));
         request.setSecondScreenShot(new FileItem(MenuaiUtils.getFile(aliPayApplyAuditDTO.getSecondScreenShot())));
         log.info("支付宝提审请求参数:{}", JSON.toJSONString(request));
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniVersionAuditApplyResponse response = (AlipayOpenMiniVersionAuditApplyResponse)alipayClient.execute(request);
         log.info("支付宝提审响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            log.info("支付宝提审成功");
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝提审失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            log.error("支付宝提审失败，原因：" + var10002 + "，" + response.getSubMsg());
            throw new ServiceException("支付宝提审失败");
         }
      } catch (AlipayApiException var5) {
         throw new ServiceException("支付宝提审异常");
      } catch (Exception var6) {
         throw new ServiceException("支付宝提审文件转换异常");
      }
   }

   public void cancelAudited(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniVersionAuditedCancelRequest alipayOpenMiniVersionAuditedCancelRequest = new AlipayOpenMiniVersionAuditedCancelRequest();
      alipayOpenMiniVersionAuditedCancelRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniVersionAuditedCancelModel model = new AlipayOpenMiniVersionAuditedCancelModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniVersionAuditedCancelRequest.setBizModel(model);
      log.info("支付宝小程序退回开发请求参数:{}", JSON.toJSONString(alipayOpenMiniVersionAuditedCancelRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniVersionAuditedCancelResponse response = (AlipayOpenMiniVersionAuditedCancelResponse)alipayClient.execute(alipayOpenMiniVersionAuditedCancelRequest);
         log.info("支付宝小程序退回开发响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            log.info("支付宝小程序退回开发成功");
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序退回开发失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序退回开发失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序退回开发异常");
      }
   }

   public void deleteAppVersion(String appVersion, String alipayAppAuthToken) {
      AlipayOpenMiniVersionDeleteRequest alipayOpenMiniVersionDeleteRequest = new AlipayOpenMiniVersionDeleteRequest();
      alipayOpenMiniVersionDeleteRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenMiniVersionDeleteModel model = new AlipayOpenMiniVersionDeleteModel();
      model.setAppVersion(appVersion);
      alipayOpenMiniVersionDeleteRequest.setBizModel(model);
      log.info("支付宝小程序删除版本请求参数:{}", JSON.toJSONString(alipayOpenMiniVersionDeleteRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenMiniVersionDeleteResponse response = (AlipayOpenMiniVersionDeleteResponse)alipayClient.execute(alipayOpenMiniVersionDeleteRequest);
         log.info("支付宝小程序删除版本响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            log.info("支付宝小程序删除版本成功");
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序删除版本失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序删除版本失败");
         }
      } catch (AlipayApiException var7) {
         throw new ServiceException("支付宝小程序删除版本异常");
      }
   }

   public void createMembers(String logonId, String role, String alipayAppAuthToken) {
      AlipayOpenAppMembersCreateRequest alipayOpenAppMembersCreateRequest = new AlipayOpenAppMembersCreateRequest();
      alipayOpenAppMembersCreateRequest.putOtherTextParam("app_auth_token", alipayAppAuthToken);
      AlipayOpenAppMembersCreateModel model = new AlipayOpenAppMembersCreateModel();
      model.setLogonId(logonId);
      model.setRole(role);
      alipayOpenAppMembersCreateRequest.setBizModel(model);
      log.info("支付宝小程序应用添加成员请求参数:{}", JSON.toJSONString(alipayOpenAppMembersCreateRequest));

      try {
         AlipayClient alipayClient = new DefaultAlipayClient(this.getClientParams());
         AlipayOpenAppMembersCreateResponse response = (AlipayOpenAppMembersCreateResponse)alipayClient.execute(alipayOpenAppMembersCreateRequest);
         log.info("支付宝小程序应用添加成员响应:{}", JSON.toJSONString(response));
         if (response.isSuccess()) {
            log.info("支付宝小程序应用添加成员成功");
         } else {
            Logger var10000 = log;
            String var10001 = response.getMsg();
            var10000.info("支付宝小程序应用添加成员失败，原因：" + var10001 + "，" + response.getSubMsg());
            String var10002 = response.getMsg();
            throw new ServiceException("支付宝小程序应用添加成员失败");
         }
      } catch (AlipayApiException var8) {
         throw new ServiceException("支付宝小程序应用添加成员异常");
      }
   }

   public String getPhone() {
      String sign = "XZaJ18jS6go02sxK9eKV2dqAIDpI9DodIp8rn17w9WhKl2Lr09perlVItm9LMwqNomR39hQyTJA9T4BVmNB+IaGok1a5UhdFifWVD4Osq93PPl063nJzFEuOkm+QeaWR6Uv7qufKPH1Sx94IOCY2NNODfA2BfN9Plwx5AdB4E5CE2+iQYeGkF3y7XBv6A/cfekpvBh51Im03pGS3UhL31waWWEf73kylMYk3e9VoKFXQweDBYie1zvbzQeK444F6UErE+8i9VYsKFQTwUwnI5Yq603plQb25B3qQSDM+9U/qO/alKEXySGRfMGnXENzRmT8mfIDB5QAZiX2iiYSGZQ==";
      String response = "IVyR/3W77K+irs1PbMKRwWERmLk2ZLxa6TjWY/qz/RFa50X9lsKN99NUF5hgC48arYqe52jm9uqJOataffnDgLoCV0SMgbVBSoiOxkmi8fMUjxtbr1j9uwLSqwgVG29+cmQ1gJmqPuy4YEizvH9aGWBQdSSB4/IiuSUeVt8ltLXT5XSzBpJaB8Ia8ZTqQ+Iz/BdNNE7DZaFoh6hNy4KujdsmgN9AOMTZR42Vja+WLsocB9hB6Oy1ETRLMG+p7Zn7nDWlRevNPf8gtaiUpy1SKaguSW6s9+6xeC0+oSCOlt+2v29aQGcbH35+KLwsK/sSlQnYtekUiso/bQr468aKe0dsszPXuq/jbD0/QTpRMZQ=";
      boolean isDataEncrypted = !response.startsWith("{");
      boolean signCheckPass = false;
      String signContent = response;
      String signVeriKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnzYG6igJ0z/Nk4zZWICkLFWbBrkqwwESTbsgeH6bYjekmOkee11KJZsGdstPDdd2exSikdF6CKTlKdg66/5TecVejipJ2Ig5LD4TGIK6dR84wpeaOShSZXoA+1elRXX+I/JmNymHigxjWsr/2E3fLkGkaiRwiOhtGqbQmbEw97D7Us5H9CJpVk7yDEQMevw4rMEk5LFmXzT6iXoDZomtIo9Tew5ncpAlKDzC/LgTT/h3yquerbyOfKNuEo1k9mLt9KfmL5f7Jc7XAeLMx74r1y2WkKzrMLUg0gh1yRoGg+IJOqbVr2/Tb5DP0D4JzmbKglseXjzoIr3siZAVQU01TwIDAQAB";
      String decryptKey = "wAKA2KqDNPKKEjNPZ00H6g==";
      if (isDataEncrypted) {
         signContent = "\"" + response + "\"";
      }

      try {
         signCheckPass = AlipaySignature.rsaCheck(signContent, sign, signVeriKey, "UTF-8", "RSA2");
      } catch (AlipayApiException var11) {
         throw new ServiceException("获取手机号验签异常");
      }

      if (!signCheckPass) {
         throw new ServiceException("获取手机号验签失败");
      } else {
         String plainData = null;
         if (isDataEncrypted) {
            try {
               plainData = AlipayEncrypt.decryptContent(response, "AES", decryptKey, "UTF-8");
            } catch (AlipayApiException var10) {
               throw new ServiceException("获取手机号解密异常");
            }
         }

         return plainData;
      }
   }

   public AlipayConfig getClientParams() {
      AlipayConfig certParams = new AlipayConfig();
      certParams.setServerUrl(this.thirdApiUrlProperties.getApialipay());
      certParams.setAppId(this.alipayProperties.getAlipayAppId());
      certParams.setPrivateKey(this.alipayProperties.getAlipayAppPrikey());
      certParams.setAlipayPublicKey(this.alipayProperties.getAlipayPublicKey());
      return certParams;
   }

   public AlipayConfig getClientParams(String appToken) {
      AlipayConfig certParams = new AlipayConfig();
      certParams.setServerUrl(this.thirdApiUrlProperties.getApialipay());
      certParams.setAppId(this.alipayProperties.getAlipayAppId());
      certParams.setPrivateKey(this.alipayProperties.getAlipayAppPrikey());
      certParams.setAlipayPublicKey(this.alipayProperties.getAlipayPublicKey());
      return certParams;
   }
}
