package com.thinkgem.jeesite.modules.pay.alipay.service;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
import com.alipay.api.request.AlipayTradeOrderSettleRequest;
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.api.response.AlipayTradeOrderSettleResponse;
import com.thinkgem.jeesite.common.config.Global;

public class AlipayService {

    public JSONObject alipay() throws AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",Global.getConfig("alipay.appid"),Global.getConfig("alipay.private.key"),"json","UTF-8",Global.getConfig("alipay.public.key"),"RSA2");
        AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest();
        request.setBizContent("{" +
                "\"out_request_no\":\"20160727001\"," +
                "\"trade_no\":\"2014030411001007850000672009\"," +
                "      \"royalty_parameters\":[{" +
                "        \"trans_out\":\"2088101126765726\"," +
                "\"trans_in\":\"2088101126708402\"," +
                "\"amount\":0.1," +
                "\"amount_percentage\":100," +
                "\"desc\":\"分账给2088101126708402\"" +
                "        }]," +
                "\"operator_id\":\"A0001\"" +
                "  }");
        AlipayTradeOrderSettleResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
        return null;
    }

    public static void main(String[] args) throws AlipayApiException {
        AlipayService alipayService = new AlipayService();
        alipayService.alipay();
    }
}
