package io.renren.demo;

import java.math.BigDecimal;

import com.alibaba.fastjson.JSON;

import io.renren.common.utils.DateUtils;
import io.renren.common.utils.HttpClientUtil;
import io.renren.vo.TransferParams;
import io.renren.vo.TransferParams.OrderInfo;
import io.renren.vo.TransferParams.PayeeInfo;
import io.renren.vo.TransferParams.PayerInfo;

/**
 * 外部代发申请 Demo
 */
public class WaiBuDaiFaDemo {
    public static void main(String[] args) throws Exception {
    	String timestamp = DateUtils.getTimestamp();
    	
    	TransferParams params = new TransferParams();
        params.setTimestamp(timestamp);
        params.setOid_partner(Constant.OidPartner);
        params.setNotify_url("https://test.lianlianpay/notify");
        params.setPay_expire("120");
        params.setFunds_flag("N");
        
        OrderInfo orderInfo = params.new OrderInfo();
        orderInfo.setTxn_seqno("WBDF_"+timestamp);
        orderInfo.setTxn_time(timestamp);
        orderInfo.setTotal_amount(new BigDecimal("15"));
        orderInfo.setTxn_purpose("佣金支付");
        orderInfo.setPostscript("佣金支付");
        orderInfo.setOrder_info("订单描述");
        params.setOrderInfo(orderInfo);
        
        PayerInfo payerInfo = params.new PayerInfo();
//        payerInfo.setPayer_type("USER");
//        payerInfo.setPayer_id("LLianPayTest-En-User-123");
        payerInfo.setPayer_type("MERCHANT");
        payerInfo.setPayer_id("2020042200284052");
        payerInfo.setPayer_accttype("MCHOWN");
//        payerInfo.setPassword(RSASign.getInstance().encrypt("112233", LLianPayConstant.LLianPayPublicKey));
//        payerInfo.setPap_agree_no(RSASign.getInstance().encrypt("2022102300275010", LLianPayConstant.LLianPayPublicKey));
        params.setPayerInfo(payerInfo);
        
        PayeeInfo payeeInfo = params.new PayeeInfo();
        payeeInfo.setPayee_type("BANKACCT_PRI");
        payeeInfo.setBank_acctno("6226662601615226");
        payeeInfo.setBank_acctname("光大银行");
        params.setPayeeInfo(payeeInfo);

        // 测试环境URL
        String url = "https://accpapi-ste.lianlianpay-inc.com/v1/txn/transfer";
        String resultJsonStr = HttpClientUtil.sendRequest(url, JSON.toJSONString(params),Constant.MerchantPrivateKey,Constant.LLianPayPublicKey);
        System.out.println(resultJsonStr);

        
    }
}
