```java

package com.intana.pay.pay;

import cn.hutool.core.util.URLUtil;

import cn.hutool.crypto.SecureUtil;

import cn.hutool.http.HttpUtil;

import com.alibaba.fastjson.JSON;

import com.intana.pay.utils.RSAUtils;

import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.Test;

import java.util.HashMap;

import java.util.Map;

/**

* 常态化对外开放支付

*/

@Slf4j

public class OpenPayTest {

private static String host="https://alipay.hhfpay.com/api";

private static String callback="http://localhost:8201";

String orderId="1690714981082509312";

static String userId="1664162429654458368";

static String urlId="1690384205761630208";

/**

* 预下单

*/

@Test

public void preOrder() throws Exception {

//预下单

createTestData();

//响应数据:{"code":200,"msg":"成功","data":"1689911276765208576"}

}

@Test

public void payNowTest(){

payNow(orderId);

}

/**

* 预下单采纳数

* @return

*/

public static Map<String, Object> createTestData() throws Exception {

Map<String, Object> testData = new HashMap<>();

testData.put("userId", userId);

testData.put("money", Double.valueOf("100.00"));

testData.put("remark", "1");

testData.put("shop", "iphone");

testData.put("urlId", urlId);

testData.put("orderType", "0");

testData.put("thirdOrderId", "8754824499483156484903");

String encode = URLUtil.encode(callback);

System.out.println(encode);

testData.put("callbackUrl", encode);

//排序

String msg = RSAUtils.getSortMsg(JSON.toJSONString(testData));

log.info("排序:{}",msg);

String s = SecureUtil.md5(msg);

System.out.println(s);

testData.put("sign", s);

//调用发起支付接口

String response = HttpUtil.post(host + "/pay/alipay/payment", JSON.toJSONString(testData));

log.info("响应数据:{}",response);

return testData;

}

/**

* 发起支付参数

* @return

*/

public static Map<String, Object> payNow(String orderId) {

Map<String, Object> testData = new HashMap<>();

testData.put("orderId", orderId);

testData.put("money", "0.1");

testData.put("urlId", urlId);

testData.put("shop", "测试");

String response = HttpUtil.post(host + "/pay/alipay/pay", JSON.toJSONString(testData));

log.info("响应数据:{}",response);

return testData;

}

}
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容