"拉卡拉进件支付代码"
This commit is contained in:
parent
1d10ffa019
commit
3c7b7ad5a7
|
|
@ -32,6 +32,7 @@ import springfox.documentation.spring.web.json.Json;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -52,19 +53,14 @@ public class LkLPayServiceImpl implements PayService {
|
||||||
@Autowired
|
@Autowired
|
||||||
MerchantBaseInfoMapper merchantBaseInfoMapper;
|
MerchantBaseInfoMapper merchantBaseInfoMapper;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RestTemplate restTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MercOrderNewService mercOrderNewService;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject tradePay(MerchantOrder order, MerchantChannelStatus channel, MerchantBaseInfo merchant) {
|
public JSONObject tradePay(MerchantOrder order, MerchantChannelStatus channel, MerchantBaseInfo merchant) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String account_type = "WECHAT";
|
String account_type = "WECHAT";
|
||||||
if (StringUtil.isNotEmpty(order.getScanType()) && "01".equals(order.getScanType())) {
|
if (StringUtil.isNotEmpty(order.getScanType()) && "01".equals(order.getScanType())) {
|
||||||
account_type = "wechatPay".equals(order.getPayTypeCode()) ? "WECHAT" : "aliPay".equals(order.getPayTypeCode()) ? "ALIPAY" : "UQRCODEPAY";
|
account_type = "wechatPay".equals(order.getPayTypeCode()) ? "WECHAT" : "aliPay".equals(order.getPayTypeCode()) ? "ALIPAY" : "UQRCODEPAY";
|
||||||
|
|
@ -87,7 +83,7 @@ public class LkLPayServiceImpl implements PayService {
|
||||||
|
|
||||||
String req_time = DateUtils.getSdfTimes();
|
String req_time = DateUtils.getSdfTimes();
|
||||||
|
|
||||||
Long order_amt = new BigDecimal(order.getConsumeFee()).multiply(new BigDecimal(100)).longValue();
|
Long order_amt = changeY2F(order.getConsumeFee());
|
||||||
String body = null;
|
String body = null;
|
||||||
if (account_type.equals("WECHAT")) {
|
if (account_type.equals("WECHAT")) {
|
||||||
body="{\n" +
|
body="{\n" +
|
||||||
|
|
@ -206,7 +202,7 @@ public class LkLPayServiceImpl implements PayService {
|
||||||
JSONObject obj = new JSONObject(6);
|
JSONObject obj = new JSONObject(6);
|
||||||
|
|
||||||
String req_time = DateUtils.getSdfTimes();
|
String req_time = DateUtils.getSdfTimes();
|
||||||
Long order_amt = new BigDecimal(order.getConsumeFee()).multiply(new BigDecimal(100)).longValue();
|
Long order_amt = changeY2F(order.getConsumeFee());
|
||||||
|
|
||||||
String body = "{\n" +
|
String body = "{\n" +
|
||||||
"\t\"req_data\": {\n" +
|
"\t\"req_data\": {\n" +
|
||||||
|
|
@ -381,4 +377,17 @@ public class LkLPayServiceImpl implements PayService {
|
||||||
public JSONObject jftPay(JftReceiptOrder order, JftMercBaseInfo jftMerc, JftMercPaymentChannel jftChannel) {
|
public JSONObject jftPay(JftReceiptOrder order, JftMercBaseInfo jftMerc, JftMercPaymentChannel jftChannel) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static long changeY2F(double price) {
|
||||||
|
DecimalFormat df = new DecimalFormat("#.00");
|
||||||
|
price = Double.valueOf(df.format(price));
|
||||||
|
long money = (long)(price * 100);
|
||||||
|
return money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
System.out.println(changeY2F(3d));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ public class LklPayService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HttpResponse post(String url, String message, String authorization, String ENCODING) throws Exception {
|
public static HttpResponse post(String url, String message, String authorization, String ENCODING) throws Exception {
|
||||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
X509TrustManager tm = new X509TrustManager() {
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -313,11 +313,11 @@ public class LklPayService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected long generateTimestamp() {
|
protected static long generateTimestamp() {
|
||||||
return System.currentTimeMillis() / 1000;
|
return System.currentTimeMillis() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateNonceStr() {
|
protected static String generateNonceStr() {
|
||||||
char[] nonceChars = new char[32];
|
char[] nonceChars = new char[32];
|
||||||
for (int index = 0; index < nonceChars.length; ++index) {
|
for (int index = 0; index < nonceChars.length; ++index) {
|
||||||
nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
|
nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
|
||||||
|
|
@ -325,7 +325,7 @@ public class LklPayService {
|
||||||
return new String(nonceChars);
|
return new String(nonceChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getAuthorization(String body, String appid, String mchSerialNo, String merchantPrivateKeyPath) throws IOException {
|
public static final String getAuthorization(String body, String appid, String mchSerialNo, String merchantPrivateKeyPath) throws IOException {
|
||||||
String nonceStr = generateNonceStr();
|
String nonceStr = generateNonceStr();
|
||||||
long timestamp = generateTimestamp();
|
long timestamp = generateTimestamp();
|
||||||
|
|
||||||
|
|
@ -335,7 +335,7 @@ public class LklPayService {
|
||||||
|
|
||||||
PrivateKey merchantPrivateKey = loadPrivateKey(new FileInputStream(new File(merchantPrivateKeyPath)));
|
PrivateKey merchantPrivateKey = loadPrivateKey(new FileInputStream(new File(merchantPrivateKeyPath)));
|
||||||
|
|
||||||
String signature = this.sign(message.getBytes("utf-8"), merchantPrivateKey);
|
String signature = sign(message.getBytes("utf-8"), merchantPrivateKey);
|
||||||
|
|
||||||
String authorization = "appid=\"" + appid + "\"," + "serial_no=\"" + mchSerialNo + "\"," + "timestamp=\""
|
String authorization = "appid=\"" + appid + "\"," + "serial_no=\"" + mchSerialNo + "\"," + "timestamp=\""
|
||||||
+ timestamp + "\"," + "nonce_str=\"" + nonceStr + "\"," + "signature=\"" + signature + "\"";
|
+ timestamp + "\"," + "nonce_str=\"" + nonceStr + "\"," + "signature=\"" + signature + "\"";
|
||||||
|
|
@ -344,7 +344,7 @@ public class LklPayService {
|
||||||
return authorization;
|
return authorization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sign(byte[] message, PrivateKey privateKey) {
|
public static String sign(byte[] message, PrivateKey privateKey) {
|
||||||
try {
|
try {
|
||||||
Signature sign = Signature.getInstance("SHA256withRSA");
|
Signature sign = Signature.getInstance("SHA256withRSA");
|
||||||
sign.initSign(privateKey);
|
sign.initSign(privateKey);
|
||||||
|
|
@ -443,4 +443,207 @@ public class LklPayService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args)throws Exception{
|
||||||
|
String appId="OP00000462",
|
||||||
|
mchSerialNo="00dfba8194c41b84cf",
|
||||||
|
privateKeyPath="D:\\project\\chaozhanggui\\pluss-common-bundle\\src\\main\\resources\\lakalaConf\\OP00000003_private_key.pem",
|
||||||
|
apiUrl="https://test.wsmsd.cn/sit/",
|
||||||
|
certificatePath="D:\\project\\chaozhanggui\\pluss-common-bundle\\src\\main\\resources\\lakalaConf\\lkl-apigw-v2.cer",
|
||||||
|
termNo="A0073841",
|
||||||
|
merchant_no="8221210594300JY",
|
||||||
|
mothod="api/v3/labs/relation/refund";
|
||||||
|
|
||||||
|
|
||||||
|
String req_time= DateUtils.getSdfTimes();
|
||||||
|
|
||||||
|
// String body="{\n" +
|
||||||
|
// " \"req_time\":\""+req_time+"\",\n" +
|
||||||
|
// " \"version\":\"3.0\",\n" +
|
||||||
|
// " \"out_org_code\":\""+appId+"\",\n" +
|
||||||
|
// " \"req_data\":{\n" +
|
||||||
|
// " \"merchant_no\":\""+merchant_no+"\",\n" +
|
||||||
|
// " \"term_no\":\""+termNo+"\",\n" +
|
||||||
|
// " \"out_trade_no\":\""+"lkl_".concat(req_time)+"\",\n" +
|
||||||
|
// " \"refund_amount\":\"1\",\n" +
|
||||||
|
// " \"refund_reason\":\"test测试退款\",\n" +
|
||||||
|
// " \"origin_out_trade_no\":\"20230608094619\",\n" +
|
||||||
|
// " \"location_info\":{\n" +
|
||||||
|
// " \"request_ip\":\"10.176.1.192\",\n" +
|
||||||
|
// " \"location\":\"+37.123456789,-121.123456789\"\n" +
|
||||||
|
// " }\n" +
|
||||||
|
// " }\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "\n";
|
||||||
|
|
||||||
|
//主扫
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\t\"out_org_code\": \""+appId+"\",\n" +
|
||||||
|
// "\t\"req_data\": {\n" +
|
||||||
|
// "\t\t\"account_type\": \"ALIPAY\",\n" +
|
||||||
|
// "\t\t\"location_info\": {\n" +
|
||||||
|
// "\t\t\t\"request_ip\": \"192.168.3.1\"\n" +
|
||||||
|
// "\t\t},\n" +
|
||||||
|
// "\t\t\"merchant_no\": \""+merchant_no+"\",\n" +
|
||||||
|
// "\t\t\"notify_url\": \"http://127.0.0.1:8080/\",\n" +
|
||||||
|
// "\t\t\"out_trade_no\": \""+req_time+"\",\n" +
|
||||||
|
// "\t\t\"term_no\": \""+termNo+"\",\n" +
|
||||||
|
// "\t\t\"total_amount\": \"1\",\n" +
|
||||||
|
// "\t\t\"trans_type\": \"41\"\n" +
|
||||||
|
// "\t},\n" +
|
||||||
|
// "\t\"req_time\": \""+req_time+"\",\n" +
|
||||||
|
// "\t\"version\": \"3.0\"\n" +
|
||||||
|
// "}";
|
||||||
|
// mothod="api/v3/labs/trans/preorder";
|
||||||
|
|
||||||
|
|
||||||
|
//扫码交易查询
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"req_time\":\""+req_time+"\",\n" +
|
||||||
|
// "\"version\":\"3.0\",\n" +
|
||||||
|
// "\"out_org_code\":\""+appId+"\",\n" +
|
||||||
|
// "\"req_data\":{\n" +
|
||||||
|
// "\"merchant_no\":\""+merchant_no+"\",\n" +
|
||||||
|
// "\"term_no\":\""+termNo+"\",\n" +
|
||||||
|
// "\"out_trade_no\":\"20230608094619\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v3/labs/query/tradequery";
|
||||||
|
|
||||||
|
//退款查询
|
||||||
|
// String body="{\n" +
|
||||||
|
// " \"req_time\":\""+req_time+"\",\n" +
|
||||||
|
// " \"version\":\"3.0\",\n" +
|
||||||
|
// " \"out_org_code\":\""+appId+"\",\n" +
|
||||||
|
// " \"req_data\":{\n" +
|
||||||
|
// " \"merchant_no\":\""+merchant_no+"\",\n" +
|
||||||
|
// " \"term_no\":\""+termNo+"\",\n" +
|
||||||
|
// " \"out_refund_order_no\":\"lkl_20230608094942\"\n" +
|
||||||
|
// " }\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "\n";
|
||||||
|
// mothod="api/v3/labs/query/idmrefundquery";
|
||||||
|
|
||||||
|
//开通主动结算业务
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// " \"version\":\"1.0\",\n" +
|
||||||
|
// "\"orderNo\":\""+req_time+"\",\n" +
|
||||||
|
// "\"orgCode\":\"1\",\n" +
|
||||||
|
// "\"merCupNo\":\""+merchant_no+"\"\n" +
|
||||||
|
// "},\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"timestamp\":\""+System.currentTimeMillis()+"\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\"\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/mms/openApi/activeSettle/apply";
|
||||||
|
|
||||||
|
//账户余额查询
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"timestamp\":"+System.currentTimeMillis()+",\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// "\"orgNo\":\"1\",\n" +
|
||||||
|
// "\"merchantNo\":\""+merchant_no+"\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/laep/industry/ewalletBalanceQuery";
|
||||||
|
|
||||||
|
//提现
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"timestamp\":\""+System.currentTimeMillis()+"\",\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// "\"orgNo\":\"1\",\n" +
|
||||||
|
// "\"merchantNo\":\""+merchant_no+"\",\n" +
|
||||||
|
// "\"drawAmt\":\"1.1\",\n" +
|
||||||
|
// "\"drawMode\":\"D0\",\n" +
|
||||||
|
// "\"notifyUrl\":\"test\",\n" +
|
||||||
|
// "\"merOrderNo\":\""+req_time+"\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/laep/industry/ewalletWithdraw";
|
||||||
|
|
||||||
|
// 提现查询
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"timestamp\":"+System.currentTimeMillis()+",\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// "\"orgNo\":\"1\",\n" +
|
||||||
|
// "\"merchantNo\":\""+merchant_no+"\",\n" +
|
||||||
|
// "\"drawJnl\":\"230608102913202588627814\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/laep/industry/ewalletWithdrawQuery";
|
||||||
|
|
||||||
|
//账管家提现模式设置
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"timestamp\":"+System.currentTimeMillis()+",\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// "\"bmcpNo\":\"1\",\n" +
|
||||||
|
// "\"mercId\":\""+merchant_no+"\",\n" +
|
||||||
|
// "\"settleType\":\"01\",\n" +
|
||||||
|
// "\"settleTime\":\"06\",\n" +
|
||||||
|
// " \"notifyUrl\":\"https://127.0.0.1/notify\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/laep/industry/ewallet/settleProfile";
|
||||||
|
|
||||||
|
//模式设置查询
|
||||||
|
// String body="{\n" +
|
||||||
|
// "\"timestamp\":"+System.currentTimeMillis()+",\n" +
|
||||||
|
// "\"ver\":\"1.0.0\",\n" +
|
||||||
|
// "\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
// "\"reqData\":{\n" +
|
||||||
|
// "\"bmcpNo\":\"1\",\n" +
|
||||||
|
// "\"mercId\":\""+merchant_no+"\"\n" +
|
||||||
|
// "}\n" +
|
||||||
|
// "}\n";
|
||||||
|
// mothod="api/v2/laep/industry/ewallet/settleQuery";
|
||||||
|
|
||||||
|
String body="{\n" +
|
||||||
|
"\"ver\":\"1.0.0\",\n" +
|
||||||
|
"\"timestamp\":\""+System.currentTimeMillis()+"\",\n" +
|
||||||
|
"\"reqId\":\""+req_time+"\",\n" +
|
||||||
|
"\"reqData\":{\n" +
|
||||||
|
"\"mercId\":\""+merchant_no+"\",\n" +
|
||||||
|
"\"termNo\":\""+termNo+"\",\n" +
|
||||||
|
"\"authCode\":\"134459859251822980\",\n" +
|
||||||
|
"\"tradeCode\":\"010304\"\n" +
|
||||||
|
"}\n" +
|
||||||
|
"}\n";
|
||||||
|
mothod="api/v2/saas/query/wx_openid_query";
|
||||||
|
|
||||||
|
String authorization = getAuthorization(body, appId, mchSerialNo, privateKeyPath);
|
||||||
|
HttpResponse lakalaResponse = post(apiUrl+ mothod, body, authorization, "utf-8");
|
||||||
|
if (lakalaResponse.getStatusLine().getStatusCode() != 200) {
|
||||||
|
log.error("请求失败,statusCode:{},message:{}", lakalaResponse.getStatusLine(), IOUtils.toString(lakalaResponse.getEntity().getContent(), "utf-8"));
|
||||||
|
MsgException.throwException(IOUtils.toString(lakalaResponse.getEntity().getContent(), "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String appid = getHeadValue(lakalaResponse, "Lklapi-Appid");
|
||||||
|
String lklapiSerial = getHeadValue(lakalaResponse, "Lklapi-Serial");
|
||||||
|
String timestamp = getHeadValue(lakalaResponse, "Lklapi-Timestamp");
|
||||||
|
String nonce = getHeadValue(lakalaResponse, "Lklapi-Nonce");
|
||||||
|
String signature = getHeadValue(lakalaResponse, "Lklapi-Signature");
|
||||||
|
String responseStr = IOUtils.toString(lakalaResponse.getEntity().getContent(), "utf-8");
|
||||||
|
System.out.println("返回的信息为 responseStr:"+responseStr);
|
||||||
|
|
||||||
|
String source = appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n";
|
||||||
|
X509Certificate lklCertificate = loadCertificate(new FileInputStream(new File(certificatePath)));
|
||||||
|
boolean verify = verify(lklCertificate, source.getBytes("utf-8"), signature);
|
||||||
|
|
||||||
|
if (verify) {
|
||||||
|
log.info("验签通过");
|
||||||
|
System.out.println(responseStr);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue