package cn.pluss.platform.util;

import java.util.HashMap;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.response.AlipayTradePayResponse;

public class PayUtil {

	public static AlipayTradePayResponse aliPay(String appAuthToken,String orderNumber,String authCode,String storeName,String orderFee) throws AlipayApiException {
		
		AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",AliPayParam.getAppId(),AliPayParam.getPri(),"json","GBK",AliPayParam.getPub(),"RSA2");
		AlipayTradePayRequest request = new AlipayTradePayRequest();
		request.putOtherTextParam("app_auth_token", appAuthToken);
		request.setBizContent("{" +
		"\"out_trade_no\":\""+orderNumber+"\"," +
		"\"scene\":\"bar_code\"," +
		"\"auth_code\":\""+authCode+"\"," +
		"\"subject\":\""+storeName+"\"," +
		"\"body\":\""+storeName+"\"," +
		"\"timeout_express\":\"1m\"," +
		"\"total_amount\":\""+orderFee+"\"" +
		"  }");
		AlipayTradePayResponse response = alipayClient.execute(request);
		return response;
	}
	
	public static String wechatPay(String code,String orderNumber,String dealFee) {
		Map<String, String> receiveDataMap = new HashMap<String, String>();
		receiveDataMap.put("appid", "wxed824282c345b7a0");
		receiveDataMap.put("mch_id", "1551169371");
		receiveDataMap.put("sub_mch_id", "1556940571");
		receiveDataMap.put("nonce_str", StringUtil.genRandomNum().toUpperCase());
		receiveDataMap.put("body", "零售商品");
		receiveDataMap.put("out_trade_no", orderNumber);
		receiveDataMap.put("total_fee", dealFee);
		receiveDataMap.put("spbill_create_ip", "60.168.58.93");
		receiveDataMap.put("auth_code", code);
		receiveDataMap.put("sign_type", "HMAC-SHA256");
		receiveDataMap.put("sign", WechatSignUtil.sha256Sign(receiveDataMap, "7F05NZBTJ3XNDK5HLSDC3H25ZXOQKDHT"));

		return WXPayHttpUtil.WXHttpPostXMLWithoutCert("https://api.mch.weixin.qq.com/pay/micropay", receiveDataMap);
	}

}
