|  | @@ -0,0 +1,147 @@
 | 
	
		
			
				|  |  | +package com.yonge.toolset.thirdparty.lingxinpay;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.utils.http.HttpUtil;
 | 
	
		
			
				|  |  | +import org.slf4j.Logger;
 | 
	
		
			
				|  |  | +import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.UUID;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * @author: cy
 | 
	
		
			
				|  |  | + * @date: 2022/5/9 11:24
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class Withdraw {
 | 
	
		
			
				|  |  | +    private static final Logger logger = LoggerFactory.getLogger(Withdraw.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCYT5eCY6r8sGWgbiId/VqSZmS6XkBNGMkzUqTIkpkecOzsFBxFXTQmgDeR991YfgqmyOaHsJ/ons/H+e8l+RmHsOm4eErFU+9qXFq+k195YFV1vAR9O7MIG+FR5vmLDuhgimPsgqscWhUrGinc8RUpi5KwClgx7d+d8ZJ4GmkR0QIDAQAB";
 | 
	
		
			
				|  |  | +    private String md5Key = "0fd42370bad6485e46718b97f3dd1536";
 | 
	
		
			
				|  |  | +    private String notifyUrl = "http://47.114.1.200:8000/teacher-server/withdraw/callback";//回调地址
 | 
	
		
			
				|  |  | +    private String memberNo = "1491663782974988288";//商户号
 | 
	
		
			
				|  |  | +    private String apiUrl = "http://39.107.15.64:8090";//第三方url
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 单笔提现
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param outerOrderNo  商户唯一订单号
 | 
	
		
			
				|  |  | +     * @param name          收款方姓名(银行预留姓名等)
 | 
	
		
			
				|  |  | +     * @param mobile        收款方电话
 | 
	
		
			
				|  |  | +     * @param certificateNo 收款方身份证号
 | 
	
		
			
				|  |  | +     * @param predictAmount 应发金额(单位为:分,范围: 1~10000000000)
 | 
	
		
			
				|  |  | +     * @param payAccount    收款方账号(银行卡号/支付宝账号 /open_id)以实际业务为准
 | 
	
		
			
				|  |  | +     * @param cardType      卡类型:DC 借记卡
 | 
	
		
			
				|  |  | +     * @param salaryType    发放类型(0:个人经营所得)
 | 
	
		
			
				|  |  | +     * @param projectName   项目名称
 | 
	
		
			
				|  |  | +     * @param payType       支付类型(1:银行卡,2:支付宝,4:微信) 以实际业务为准
 | 
	
		
			
				|  |  | +     * @param cardAttribute 卡属性:(C:对私)
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public String withdraw(String outerOrderNo, String name, String mobile, String certificateNo, String predictAmount,
 | 
	
		
			
				|  |  | +                           String payAccount, String cardType, String salaryType, String projectName, String payType, String cardAttribute) {
 | 
	
		
			
				|  |  | +        Map<String, Object> map = new HashMap<>();
 | 
	
		
			
				|  |  | +        map.put("outMemberNo", memberNo);
 | 
	
		
			
				|  |  | +        map.put("outerOrderNo", outerOrderNo);
 | 
	
		
			
				|  |  | +        map.put("name", name);
 | 
	
		
			
				|  |  | +        map.put("certificateNo", certificateNo);
 | 
	
		
			
				|  |  | +        map.put("predictAmount", predictAmount);
 | 
	
		
			
				|  |  | +        String signs = Md5EncryptUtils.sign(map, md5Key);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        map.put("charset", "UTF-8");
 | 
	
		
			
				|  |  | +        map.put("mobile", mobile);
 | 
	
		
			
				|  |  | +        map.put("version", "1.1");
 | 
	
		
			
				|  |  | +        map.put("service", "bpotop.zx.pay.order");
 | 
	
		
			
				|  |  | +        map.put("Md5Key", signs);
 | 
	
		
			
				|  |  | +        map.put("notifyUrl", notifyUrl);
 | 
	
		
			
				|  |  | +        map.put("cardType", cardType);
 | 
	
		
			
				|  |  | +        map.put("salaryType", salaryType);
 | 
	
		
			
				|  |  | +        map.put("projectName", projectName);
 | 
	
		
			
				|  |  | +        map.put("payType", payType);
 | 
	
		
			
				|  |  | +        map.put("cardAttribute", cardAttribute);
 | 
	
		
			
				|  |  | +        map.put("payAccount", payAccount);
 | 
	
		
			
				|  |  | +        String jsonStr = JSONObject.toJSONString(map);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //签名
 | 
	
		
			
				|  |  | +        JSONObject mapParam = new JSONObject();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //使用公钥加密
 | 
	
		
			
				|  |  | +            String encryptStr = RSA.encryptPub(jsonStr, publicKey);
 | 
	
		
			
				|  |  | +            mapParam.put("outMemberNo", memberNo);
 | 
	
		
			
				|  |  | +            mapParam.put("signType", "RSA");
 | 
	
		
			
				|  |  | +            mapParam.put("sign", encryptStr);
 | 
	
		
			
				|  |  | +            logger.info("单笔请求请求参数:{}", JSONObject.toJSONString(mapParam));
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            logger.info("加密失败:{}", e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //发送
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            String resultJsonStr = HttpUtil.postForHttp(apiUrl + "/bpotop_trade/single", JSONObject.toJSONString(mapParam), null);
 | 
	
		
			
				|  |  | +            logger.info("单笔请求返回参数:{}", resultJsonStr);
 | 
	
		
			
				|  |  | +            return resultJsonStr;
 | 
	
		
			
				|  |  | +        } catch (IOException e) {
 | 
	
		
			
				|  |  | +            logger.info("发送失败:{}", e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 查询接口
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param outerOrderNo 商户唯一订单号
 | 
	
		
			
				|  |  | +     * @throws Exception
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void query(String outerOrderNo) throws Exception {
 | 
	
		
			
				|  |  | +        Map<String, Object> requestMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        requestMap.put("outMemberNo", memberNo);
 | 
	
		
			
				|  |  | +        requestMap.put("outerOrderNo", outerOrderNo);
 | 
	
		
			
				|  |  | +        requestMap.put("service", "bpotop.zx.pay.order");
 | 
	
		
			
				|  |  | +        requestMap.put("version", "1.0");
 | 
	
		
			
				|  |  | +        requestMap.put("signType", "RSA");
 | 
	
		
			
				|  |  | +        requestMap.put("charset", "UTF-8");
 | 
	
		
			
				|  |  | +        String jsonStr = JSONObject.toJSONString(requestMap);
 | 
	
		
			
				|  |  | +        String encryptStr = RSA.encryptPub(jsonStr, publicKey);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map<String, Object> requestMap2 = new HashMap<>();
 | 
	
		
			
				|  |  | +        requestMap2.put("outMemberNo", memberNo);
 | 
	
		
			
				|  |  | +        requestMap2.put("sign", encryptStr);
 | 
	
		
			
				|  |  | +        logger.info("单笔查询请求参数:{}", JSONObject.toJSONString(requestMap2));
 | 
	
		
			
				|  |  | +        String resultJsonStr = HttpUtil.postForHttp(apiUrl + "/bpotop_trade/order_query", JSONObject.toJSONString(requestMap2), null);
 | 
	
		
			
				|  |  | +        logger.info("单笔查询响应参数:{}", resultJsonStr);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static void main(String[] args) throws Exception {
 | 
	
		
			
				|  |  | +        Withdraw withdraw = new Withdraw();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //输入商户订单号
 | 
	
		
			
				|  |  | +        String outerOrderNo = UUID.randomUUID().toString().substring(0, 12);
 | 
	
		
			
				|  |  | +        //输入收款人手机号
 | 
	
		
			
				|  |  | +        String name = "何亮";
 | 
	
		
			
				|  |  | +        //输入收款人姓名
 | 
	
		
			
				|  |  | +        String mobile = "17600220933";
 | 
	
		
			
				|  |  | +        //输入收款人身份证号
 | 
	
		
			
				|  |  | +        String certificateNo = "130423199206192818";
 | 
	
		
			
				|  |  | +        //输入转账金额(单位分)
 | 
	
		
			
				|  |  | +        String predictAmount = "1";
 | 
	
		
			
				|  |  | +        //输入收款人账号
 | 
	
		
			
				|  |  | +        String payAccount = "6228480018864836772";
 | 
	
		
			
				|  |  | +        //输入卡类型:DC借记卡,CC信用卡(暂不支持)
 | 
	
		
			
				|  |  | +        String cardType = "DC";
 | 
	
		
			
				|  |  | +        //输入发放类型(0:工资,1:奖金,2:绩效,3:劳务,4:个人经营所得,5:其他)
 | 
	
		
			
				|  |  | +        String salaryType = "4";
 | 
	
		
			
				|  |  | +        //输入项目名称
 | 
	
		
			
				|  |  | +        String projectName = "测试";
 | 
	
		
			
				|  |  | +        //输入支付类型(1:银行卡)
 | 
	
		
			
				|  |  | +        String payType = "1";
 | 
	
		
			
				|  |  | +        //输入卡属性:(C:对私 ,B:对公)暂时不支持对公
 | 
	
		
			
				|  |  | +        String cardAttribute = "C";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String requestParam = withdraw.withdraw(outerOrderNo, name, mobile, certificateNo, predictAmount, payAccount, cardType,
 | 
	
		
			
				|  |  | +                salaryType, projectName, payType, cardAttribute);
 | 
	
		
			
				|  |  | +        logger.info("单笔请求返回参数:{}", requestParam);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |