package com.hxh.spring.test;
|
|
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.internal.util.AlipaySignature;
|
import com.yeshi.buwan.util.user.VipUtil;
|
import org.json.JSONObject;
|
import org.junit.Test;
|
import org.yeshi.utils.alipay.AlipayH5PayUtil;
|
import org.yeshi.utils.entity.alipay.AlipayAppInfo;
|
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.Map;
|
import java.util.Properties;
|
|
public class AlipayTest {
|
|
|
private AlipayAppInfo getAppInfo() {
|
Properties properties = new Properties();
|
try {
|
properties.load(AlipayTest.this.getClass().getClassLoader().getResourceAsStream("alipay.properties"));
|
String privateKey = properties.getProperty("private_key");
|
String publicKey = properties.getProperty("alipay_public_key");
|
AlipayAppInfo appInfo = new AlipayAppInfo("2021002122664142", privateKey, publicKey);
|
return appInfo;
|
} catch (Exception e) {
|
|
}
|
return null;
|
|
}
|
|
@Test
|
public void test1() {
|
Properties properties = new Properties();
|
try {
|
properties.load(AlipayTest.this.getClass().getClassLoader().getResourceAsStream("alipay.properties"));
|
String privateKey = properties.getProperty("private_key");
|
String publicKey = properties.getProperty("alipay_public_key");
|
System.out.println(privateKey);
|
System.out.println(publicKey);
|
String orderNo = "123123";
|
BigDecimal money = new BigDecimal("0.1");
|
String goodsTitle = "影视大全会员充值";
|
String returnUrl = "http://vip.ysdq.yeshitv.com";
|
String notifyUrl = "http://api.ysdq.yeshitv.com:8089/BuWan/api/callback/alipay";
|
AlipayAppInfo appInfo = new AlipayAppInfo("2021002122664142", privateKey, publicKey);
|
String form = AlipayH5PayUtil.createOrderForm(appInfo, orderNo, money, goodsTitle, returnUrl, notifyUrl);
|
System.out.println(form);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} catch (AlipayApiException e) {
|
e.printStackTrace();
|
}
|
|
|
}
|
|
@Test
|
public void testSign() {
|
String result = "{\"gmt_create\":\"2021-01-10 15:43:01\",\"charset\":\"GBK\",\"seller_email\":\"pay@banliapp.com\",\"subject\":\"影视大全会员充值\",\"sign\":\"HaLg1jxJBbO1V8yS52g+7amfOc5YpooTW3rEBJ6us0dNuk76em9LZGF6nrvgmAiftxKiDC6iItK9OM7/UJLDVoRs6KMuIhrheWILEwob+x6bN3360sGos+e3aEc6DFxCAEcqg8L3221+zubXsx/hUAkSWe6l87aRI+L1fxesnQ3CFsRTOoRFdI0BlbD3CBi+NG4M0BN0zMIqOTUHv/nWnLgoseJeYSv1xvlarVO98vPWRLb+fwx1HYh/xFtItYvZgS3J8CDG/faKAAi/OoTDXJBh82RuEn3q1yC/5SP9iiplvOmzXvCludfjjTncICXX9Jcy/ljXNhbF8wUDxB26KQ==\",\"buyer_id\":\"2088812685461771\",\"invoice_amount\":\"0.01\",\"notify_id\":\"2021011000222154302061771416253509\",\"fund_bill_list\":\"[{\\\"amount\\\":\\\"0.01\\\",\\\"fundChannel\\\":\\\"PCREDIT\\\"}]\",\"notify_type\":\"trade_status_sync\",\"trade_status\":\"TRADE_SUCCESS\",\"receipt_amount\":\"0.01\",\"buyer_pay_amount\":\"0.01\",\"app_id\":\"2021002122664142\",\"sign_type\":\"RSA2\",\"seller_id\":\"2088231353656741\",\"gmt_payment\":\"2021-01-10 15:43:02\",\"notify_time\":\"2021-01-10 15:43:02\",\"version\":\"1.0\",\"out_trade_no\":\"202101101542\",\"total_amount\":\"0.01\",\"trade_no\":\"2021011022001461771414408457\",\"auth_app_id\":\"2021002122664142\",\"buyer_logon_id\":\"185****8252\",\"point_amount\":\"0.00\"}\n";
|
|
JSONObject jsonObject = new JSONObject(result);
|
Map<String, String> map = new HashMap<>();
|
for (Iterator<String> its = jsonObject.keys(); its.hasNext(); ) {
|
String key = its.next();
|
String value = jsonObject.optString(key);
|
map.put(key, value);
|
}
|
|
|
AlipayAppInfo app = VipUtil.getAlipayApp();
|
|
try {
|
boolean signRight = AlipaySignature.rsaCheckV1(map, app.getAlipayPublicKey(), "GBK", map.get("sign_type"));
|
System.out.println(signRight);
|
} catch (AlipayApiException e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
@Test
|
public void refound() {
|
String orderNo = "buwan_vip_48";
|
try {
|
AlipayH5PayUtil.refund(getAppInfo(), orderNo, null, new BigDecimal("14.8"), orderNo+"_1");
|
} catch (AlipayApiException e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
}
|