package com.ruoyi.shop.util;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.github.binarywang.wxpay.bean.ecommerce.*;
|
import com.github.binarywang.wxpay.bean.media.ImageUploadResult;
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
import com.github.binarywang.wxpay.service.EcommerceService;
|
import com.github.binarywang.wxpay.service.MerchantMediaService;
|
import com.github.binarywang.wxpay.service.WxPayService;
|
import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication;
|
import com.ruoyi.system.api.domain.poji.shop.Shop;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Component;
|
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 微信支付
|
*/
|
@Component
|
@AllArgsConstructor
|
public class WechatPayUtils {
|
|
private final WxPayService wxService;
|
|
/**
|
* @description 电商二级商户进件(提交申请单)
|
* @author jqs
|
* @date 2023/8/11 10:04
|
* @param shopAuthentication
|
* @param applyNumber
|
* @param shop
|
* @return ApplymentsResult
|
*/
|
public ApplymentsResult ecommerceApply(ShopAuthentication shopAuthentication, String applyNumber, Shop shop) throws Exception {
|
EcommerceService ecommerceService = wxService.getEcommerceService();
|
MerchantMediaService merchantMediaService = wxService.getMerchantMediaService();
|
ApplymentsRequest request = new ApplymentsRequest();
|
//生成提交类
|
request.setOutRequestNo(applyNumber);
|
if(shopAuthentication.getMainType()==2){
|
request.setOrganizationType("2");
|
}else{
|
request.setOrganizationType("4");
|
}
|
//营业执照
|
ApplymentsRequest.BusinessLicenseInfo business_license_info = new ApplymentsRequest.BusinessLicenseInfo();
|
InputStream blImageIO = OBSUploadUtils.getOSSInputStream(shopAuthentication.getBlImage().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult blImageIR = merchantMediaService.imageUploadV3(blImageIO,applyNumber+"blimage.jpg");
|
business_license_info.setBusinessLicenseCopy(blImageIR.getMediaId());
|
blImageIO.close();
|
business_license_info.setBusinessLicenseNumber(shopAuthentication.getBlNumber());
|
business_license_info.setMerchantName(shopAuthentication.getBlShopName());
|
business_license_info.setLegalPerson(shopAuthentication.getBlCorporateName());
|
business_license_info.setCompanyAddress(shopAuthentication.getBlRegisteredAddress());
|
List<String> businessTimeList = new ArrayList<>();
|
businessTimeList.add(0,shopAuthentication.getBlBusinessStartTime());
|
businessTimeList.add(1,shopAuthentication.getBlBusinessDeanline());
|
if(businessTimeList!=null&&businessTimeList.size()>1){
|
String businessTime = JSONObject.toJSONString(businessTimeList);
|
business_license_info.setBusinessTime(businessTime);
|
}
|
request.setBusinessLicenseInfo(business_license_info);
|
//法人证件
|
request.setIdDocType("IDENTIFICATION_TYPE_MAINLAND_IDCARD");
|
ApplymentsRequest.IdCardInfo id_card_info = new ApplymentsRequest.IdCardInfo();
|
InputStream lpIcFrontIO = OBSUploadUtils.getOSSInputStream(shopAuthentication.getLpIcFront().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult lpIcFrontIR = merchantMediaService.imageUploadV3(lpIcFrontIO,applyNumber+"lpIcFront.jpg");
|
id_card_info.setIdCardCopy(lpIcFrontIR.getMediaId());
|
lpIcFrontIO.close();
|
InputStream lpIcBackIO = OBSUploadUtils.getOSSInputStream(shopAuthentication.getLpIcBack().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult lpIcBackIR = merchantMediaService.imageUploadV3(lpIcBackIO,applyNumber+"lpIcBack.jpg");
|
id_card_info.setIdCardNational(lpIcBackIR.getMediaId());
|
lpIcBackIO.close();
|
id_card_info.setIdCardName(shopAuthentication.getLpCorporateName());
|
id_card_info.setIdCardNumber(shopAuthentication.getLpIdCard());
|
if(shopAuthentication.getMainType()==2){
|
id_card_info.setIdCardAddress(shopAuthentication.getLpIdAddress());
|
}
|
id_card_info.setIdCardValidTimeBegin(shopAuthentication.getLpIcStartDate());
|
id_card_info.setIdCardValidTime(shopAuthentication.getLpIcEndDate());
|
request.setIdCardInfo(id_card_info);
|
//企业填写
|
if(shopAuthentication.getMainType()==2){
|
//受益人
|
if(shopAuthentication.getOwner()==1){
|
request.setOwner(true);
|
}else{
|
request.setOwner(false);
|
List<ApplymentsRequest.UboInfo> ubo_info_list = new ArrayList<>();
|
ApplymentsRequest.UboInfo uboInfo = new ApplymentsRequest.UboInfo();
|
uboInfo.setUboIdDocType("IDENTIFICATION_TYPE_MAINLAND_IDCARD");
|
InputStream uboIcFrontIO = OBSUploadUtils.getOSSInputStream(shopAuthentication.getUboIcFront().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult uboIcFrontIR = merchantMediaService.imageUploadV3(uboIcFrontIO,applyNumber+"uboIcFront.jpg");
|
uboInfo.setUboIdDocCopy(uboIcFrontIR.getMediaId());
|
uboIcFrontIO.close();
|
InputStream uboIcBackIO = OBSUploadUtils.getOSSInputStream(shopAuthentication.getUboIcBack().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult uboIcBackIR = merchantMediaService.imageUploadV3(uboIcBackIO,applyNumber+"uboIcBack.jpg");
|
uboInfo.setUboIdDocCopyBack(uboIcBackIR.getMediaId());
|
uboIcBackIO.close();
|
uboInfo.setUboIdDocName(shopAuthentication.getUboName());
|
uboInfo.setUboIdDocNumber(shopAuthentication.getUboIdCard());
|
uboInfo.setUboIdDocAddress(shopAuthentication.getUboIcAddress());
|
uboInfo.setUboIdDocPeriodBegin(shopAuthentication.getUboIcStartDate());
|
ubo_info_list.add(uboInfo);
|
request.setUboInfoList(ubo_info_list);
|
}
|
}
|
//结算账户信息
|
ApplymentsRequest.AccountInfo accountInfo = new ApplymentsRequest.AccountInfo();
|
if(shopAuthentication.getSettlementAccountType().equals("1")){
|
accountInfo.setBankAccountType("74");
|
}else{
|
accountInfo.setBankAccountType("75");
|
}
|
accountInfo.setAccountBank(shopAuthentication.getSaBank());
|
accountInfo.setAccountName(shopAuthentication.getSaAccountName());
|
accountInfo.setBankAddressCode(shopAuthentication.getSaBankCityCode());
|
accountInfo.setBankName(shopAuthentication.getSaBankName());
|
accountInfo.setAccountNumber(shopAuthentication.getSaNumber());
|
request.setAccountInfo(accountInfo);
|
ApplymentsRequest.ContactInfo contactInfo = new ApplymentsRequest.ContactInfo();
|
contactInfo.setContactType("65");
|
contactInfo.setContactName(shopAuthentication.getLpCorporateName());
|
contactInfo.setContactIdCardNumber(shopAuthentication.getLpIdCard());
|
contactInfo.setMobilePhone(shopAuthentication.getLpMobilePhone());
|
contactInfo.setContactEmail(shopAuthentication.getLpContactEmail());
|
request.setContactInfo(contactInfo);
|
//店铺信息
|
ApplymentsRequest.SalesSceneInfo salesSceneInfo = new ApplymentsRequest.SalesSceneInfo();
|
salesSceneInfo.setStoreName(shop.getShopName());
|
InputStream storeQrCodeIO = OBSUploadUtils.getOSSInputStream(shop.getShopCode().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
|
ImageUploadResult storeQrCodeIR = merchantMediaService.imageUploadV3(storeQrCodeIO,applyNumber+"storeQrCode.jpg");
|
salesSceneInfo.setStoreQrCode(storeQrCodeIR.getMediaId());
|
storeQrCodeIO.close();
|
request.setSalesSceneInfo(salesSceneInfo);
|
request.setMerchantShortname(shop.getShopName());
|
request.setBusinessAdditionPics(shopAuthentication.getBaPics());
|
request.setBusinessAdditionDesc(shopAuthentication.getBaDesc());
|
return ecommerceService.createApply(request);
|
}
|
|
|
/**
|
* @description 查询申请审核状态
|
* @author jqs
|
* @date 2023/8/11 10:04
|
* @param applymentId
|
* @return ApplymentsStatusResult
|
*/
|
public ApplymentsStatusResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException {
|
return wxService.getEcommerceService().queryApplyStatusByApplymentId(applymentId);
|
}
|
|
public ProfitSharingReceiverResult addProfitSharingReceiver(ProfitSharingReceiverRequest request) throws WxPayException {
|
request.setAppid("wxb7f0ea286fc4e535");
|
request.setType("MERCHANT_ID");
|
request.setRelationType("SERVICE_PROVIDER");
|
ProfitSharingReceiverResult result = wxService.getEcommerceService().addReceivers(request);
|
return result;
|
}
|
}
|