44323
2023-10-30 9d19ca02aa30c4d486a4cfe861d698d454ce8d5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.dsh.guns.modular.system.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.Shop;
import com.dsh.course.util.UUIDUtil;
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.controller.util.UploadUtil;
import com.dsh.guns.modular.system.model.OperatorAuth;
import com.dsh.guns.modular.system.model.TOperator;
import com.dsh.guns.modular.system.model.User;
import com.dsh.guns.modular.system.service.IUserService;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsRequest;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsResult;
import com.github.binarywang.wxpay.bean.media.ImageUploadResult;
import com.github.binarywang.wxpay.service.EcommerceService;
import com.github.binarywang.wxpay.service.MerchantMediaService;
import com.github.binarywang.wxpay.service.WxPayService;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
 
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 微信工具类
 */
@Component
public class WeChatUtil {
 
    private  WxPayService wxService;
 
 
 
    /**
     * @description  电商二级商户进件(提交申请单)
     * @author  jqs
     * @date    2023/8/11 10:04
     * @param shopAuthentication
     * @param applyNumber
     * @param operator
     * @return  ApplymentsResult
     */
 
 
    public  ApplymentsResult ecommerceApply(OperatorAuth shopAuthentication, String applyNumber, TOperator operator) throws Exception {
 
        EcommerceService ecommerceService = wxService.getEcommerceService();
        MerchantMediaService merchantMediaService = wxService.getMerchantMediaService();
        ApplymentsRequest request = new ApplymentsRequest();
        //生成提交类
        request.setOutRequestNo(applyNumber);
        if("ENTERPRISE".equals(shopAuthentication.getBodyType())){
            request.setOrganizationType("2");
        }else{
            request.setOrganizationType("4");
        }
        //营业执照
        ApplymentsRequest.BusinessLicenseInfo business_license_info = new ApplymentsRequest.BusinessLicenseInfo();
        InputStream blImageIO = OBSUploadUtil.getOBSStream(shopAuthentication.getBusinessPicture().replace("https://obs.ap-southeast-4.myhuaweicloud.com/",""));
        ImageUploadResult blImageIR = merchantMediaService.imageUploadV3(blImageIO,applyNumber+"blimage.jpg");
        business_license_info.setBusinessLicenseCopy(blImageIR.getMediaId());
        blImageIO.close();
        business_license_info.setBusinessLicenseNumber(shopAuthentication.getBusinessNumber());
        business_license_info.setMerchantName(shopAuthentication.getBusinessName());
        business_license_info.setLegalPerson(shopAuthentication.getLegalPerson());
        business_license_info.setCompanyAddress(shopAuthentication.getRegisterAddress());
        List<String> businessTimeList = new ArrayList<>();
        businessTimeList.add(0,shopAuthentication.getBusinessTerm());
        businessTimeList.add(1,shopAuthentication.getBusinessEnd());
        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 = OBSUploadUtil.getOBSStream(shopAuthentication.getLegalFront().replace("https://obs.ap-southeast-4.myhuaweicloud.com/",""));
        ImageUploadResult lpIcFrontIR = merchantMediaService.imageUploadV3(lpIcFrontIO,applyNumber+"lpIcFront.jpg");
        id_card_info.setIdCardCopy(lpIcFrontIR.getMediaId());
        lpIcFrontIO.close();
        InputStream lpIcBackIO = OBSUploadUtil.getOBSStream(shopAuthentication.getLegalBack().replace("https://obs.ap-southeast-4.myhuaweicloud.com/",""));
        ImageUploadResult lpIcBackIR = merchantMediaService.imageUploadV3(lpIcBackIO,applyNumber+"lpIcBack.jpg");
        id_card_info.setIdCardNational(lpIcBackIR.getMediaId());
        lpIcBackIO.close();
        id_card_info.setIdCardName(shopAuthentication.getLegalPerson());
        id_card_info.setIdCardNumber(shopAuthentication.getLeagleNumber());
        if("ENTERPRISE".equals(shopAuthentication.getBodyType())){
            id_card_info.setIdCardAddress(shopAuthentication.getLegalAddress());
        }
        id_card_info.setIdCardValidTimeBegin(shopAuthentication.getLegalTerm());
        id_card_info.setIdCardValidTime(shopAuthentication.getLegalEnd());
        request.setIdCardInfo(id_card_info);
        //企业填写
        if("ENTERPRISE".equals(shopAuthentication.getBodyType())){
            //受益人
            if("true".equals(shopAuthentication.getIsBeneficiary())){
                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 = OBSUploadUtil.getOBSStream(shopAuthentication.getBeneficiaryFront().replace("https://obs.ap-southeast-4.myhuaweicloud.com/",""));
                ImageUploadResult uboIcFrontIR = merchantMediaService.imageUploadV3(uboIcFrontIO,applyNumber+"uboIcFront.jpg");
                uboInfo.setUboIdDocCopy(uboIcFrontIR.getMediaId());
                uboIcFrontIO.close();
                InputStream uboIcBackIO = OBSUploadUtil.getOBSStream(shopAuthentication.getBeneficiaryBack().replace("https://obs.ap-southeast-4.myhuaweicloud.com/",""));
                ImageUploadResult uboIcBackIR = merchantMediaService.imageUploadV3(uboIcBackIO,applyNumber+"uboIcBack.jpg");
                uboInfo.setUboIdDocCopyBack(uboIcBackIR.getMediaId());
                uboIcBackIO.close();
                uboInfo.setUboIdDocName(shopAuthentication.getBeneficiary());
                uboInfo.setUboIdDocNumber(shopAuthentication.getBeneficiaryNumber());
                uboInfo.setUboIdDocAddress(shopAuthentication.getBeneficiaryAddress());
                uboInfo.setUboIdDocPeriodBegin(shopAuthentication.getBeneficiaryTerm());
                ubo_info_list.add(uboInfo);
                request.setUboInfoList(ubo_info_list);
            }
        }
        //结算账户信息
        ApplymentsRequest.AccountInfo accountInfo = new ApplymentsRequest.AccountInfo();
        if(shopAuthentication.getAccountType().equals(1)){
            accountInfo.setBankAccountType("74");
        }else{
            accountInfo.setBankAccountType("75");
        }
        accountInfo.setAccountBank(shopAuthentication.getBank());
        accountInfo.setAccountName(shopAuthentication.getAccountName());
        accountInfo.setBankAddressCode(shopAuthentication.getCityCode());
        accountInfo.setBankName(shopAuthentication.getBankName());
        accountInfo.setAccountNumber(shopAuthentication.getBankNumber());
        request.setAccountInfo(accountInfo);
        ApplymentsRequest.ContactInfo contactInfo = new ApplymentsRequest.ContactInfo();
        contactInfo.setContactType("65");
        contactInfo.setContactName(shopAuthentication.getLegalPerson());
        contactInfo.setContactIdCardNumber(shopAuthentication.getLeagleNumber());
        contactInfo.setMobilePhone(shopAuthentication.getLegalPhone());
        contactInfo.setContactEmail(shopAuthentication.getLegalEmail());
        request.setContactInfo(contactInfo);
        //店铺信息
        ApplymentsRequest.SalesSceneInfo salesSceneInfo = new ApplymentsRequest.SalesSceneInfo();
        salesSceneInfo.setStoreName(operator.getName());
//        InputStream storeQrCodeIO = OBSUploadUtils.getOSSInputStream(operator.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(operator.getName());
//        request.setBusinessAdditionPics(shopAuthentication.getBaPics());
//        request.setBusinessAdditionDesc(shopAuthentication.getBaDesc());
        return ecommerceService.createApply(request);
    }
   
}