com.tmsps.ne4Weixin.api.PaymentAPI Maven / Gradle / Ivy
The newest version!
package com.tmsps.ne4Weixin.api;
import java.util.Map;
import com.tmsps.ne4Weixin.config.WxConfig;
import com.tmsps.ne4Weixin.utils.HttpClient;
import com.tmsps.ne4Weixin.utils.PaymentUtil;
import com.tmsps.ne4Weixin.utils.XmlHelper;
public class PaymentAPI extends BaseAPI {
public PaymentAPI(WxConfig config) {
super(config);
}
/**
* 交易类型https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1
*/
public static enum TradeType {
JSAPI, NATIVE, APP, WAP
}
// 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
private static final String WXPAYURL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
/**
* 微信下单
*/
public Map requestOrder(Map params) {
params.put("nonce_str", System.currentTimeMillis() + "");
String sign = PaymentUtil.createSign(params, config.getPayAPI());
params.put("sign", sign);
String xmlStr = HttpClient.postXML(WXPAYURL, PaymentUtil.toXml(params));
return XmlHelper.of(xmlStr).toMap();
}
}