JAVA接入讯虎支付接口调用
@RestController@RequestMapping("/payment")
public class XunhupayController {
@PostMapping("pay")
public String pay () {
// appid
String appid = "2019061250......;
// appsecret
String appsecret = "95c75affab606258fc.......";
// 请求路径
String url = "https://api.xunhupay.com/payment/do.html";
// 设置 传递参数的集合,方便 传递数据。
Map options = new HashMap<>();
// 必填 设置版本号
options.put("version","1.1");
// 必填 设置 appid
options.put("appid",appid);
// 密钥不需要直接传递
//options.put("appsecret",appsecret);
// 必填 订单号 具体内容自己控制 长度 32位 官网说 请确保在当前网站内是唯一订单号,具体含义 我测试了 在描述 此备注
options.put("trade_order_id","1");
// 必填 价格 精确到RMB分
options.put("total_fee","0.01");
// 必填 标题
options.put("title","测试使用的title");
// 必填 当前时间戳 调用 刚写的方法 getSecondTimestamp
options.put("time", getSecondTimestamp(new Date()));
// 必填 通知回调地址 url 什么含义 我们后台需要知道 用户支付了。
options.put("notify_url","https://zanglikun.cn1.utools.club/paycallback"); // 只有这个有用
// 非必填 使用 响应字段中 url 就直接跳到百度了,如果访问,url_qrcode ,不会直接跳转,只有当支付完成后,再次刷新 url_qrcode中的连接,才会跳转。
options.put("return_url","http://localhost:8080/pages/xunhupay/payok.html");
// 非必填 用户取消支付,跳转的页面 经过测试,没有触发机制,建议不传递
options.put("callback_url","https://www.sina.com.cn/");
//plugins 非必填 备注信息
options.put("plugins","我是备注信息");
// nonce_str必填 随机值 32位内作用: 1.避免服务器页面缓存,2.防止安全密钥被猜测出来(md5 密钥越复杂,就越难解密出来)
options.put("nonce_str","740969606");
// 定义 sb 为了获取 MD5 加密前的字符串
StringBuilder sb = new StringBuilder();
// 将HashMap 进行 键 的 Ascll 从小到大排序 并 将每个 hashmap元素 以 & 拼接起来
options.entrySet().stream().sorted((e1,e2) -> e1.getKey().compareTo(e2.getKey())).forEach(a ->{
sb.append(a).append("&");});
// 去除 最后一位的 &
sb.deleteCharAt(sb.length()-1);
// 拼接上密钥
sb.append(appsecret);
// 调用 Hutool 的 加密工具 进行 MD5 加密
String s = SecureUtil.md5(sb.toString());
// 输出hash结果 postman 要用
System.out.println("我们生成的Hash 是:"+s);
// 输出time结果 postman 要用
System.out.println("我们生成的time 是: "+options.get("time"));
System.out.println();
// 必填 hash 签名
options.put("hash", s);
System.out.println("我们传递的参数有:"+options.toString());
System.out.println("开始调 虎皮椒支付 接口...");
// 调用 Hutool 的HttpUtil 发送 post 请求
String post = HttpUtil.post(url, options);
System.out.println("结束调 虎皮椒支付 接口...\n");
System.out.println("虎皮椒支付 接口 响应的结果是:"+post+"\n");
// 说明:这里 因为虎皮椒支付 响应结果 不统一,正确是Json;不正确 就是一行String 。没办法 判断是否请求是否有效。所以 只能通过 是由能够解析成json 有无异常判断 是否调用成功
try{
Map map = (Map) JSON.parse(post);
map.keySet().stream().forEach(k -> {
if (k == "url") {
System.out.println("url二维码链接是: "+map.get(k));
}
});
}catch (Exception e){
e.printStackTrace();
System.out.println("调 虎皮椒支付 时 出现了问题");
}
returnpost;
}
/**
* 获取精确到秒的时间戳 原理 获取毫秒时间戳,因为 1秒 = 100毫秒 去除后三位 就是秒的时间戳
* @return
*/
public static int getSecondTimestamp(Date date){
if (null == date) {
return 0;
}
String timestamp = String.valueOf(date.getTime());
int length = timestamp.length();
if (length > 3) {
return Integer.valueOf(timestamp.substring(0,length-3));
} else {
return 0;
}
}
@RequestMapping("/query")
@ResponseBody
public String query(){
Map options = new HashMap<>();
// appid
String appid = "201906125050";
// appsecret
String appsecret = "95c75affab606258fca4942d89dc1b4e";
//https://api.xunhupay.com/payments/wechat/index?id=20213321543&
// nonce_str=0130460042&time=1642003004&appid=201906125050&hash=3eeea1c287cf9310b6ef395a9b04d313
// 必填 设置 appid
options.put("appid","201906125050");
// 商户网站订单号
options.put("out_trade_order","1");
// 虎皮椒内部订单号
options.put("open_order_id","20213321543");
// 当前时间戳
options.put("time",getSecondTimestamp(new Date()));
// 随机值
options.put("nonce_str","0130460042");
// 定义 sb 为了获取 MD5 加密前的字符串
StringBuilder sb = new StringBuilder();
// 将HashMap 进行 键 的 Ascll 从小到大排序 并 将每个 hashmap元素 以 & 拼接起来
options.entrySet().stream().sorted((e1,e2) -> e1.getKey().compareTo(e2.getKey())).forEach(a ->{
sb.append(a).append("&");});
// 去除 最后一位的 &
sb.deleteCharAt(sb.length()-1);
// 拼接上密钥
sb.append(appsecret);
// 调用 Hutool 的 加密工具 进行 MD5 加密
String s = SecureUtil.md5(sb.toString());
// 输出hash结果 postman 要用
System.out.println("我们生成的Hash 是:"+s);
// 输出time结果 postman 要用
System.out.println("我们生成的time 是: "+options.get("time"));
System.out.println();
// 必填 hash 签名
options.put("hash", s);
// 调用 Hutool 的HttpUtil 发送 post 请求
String post = HttpUtil.post("https://api.xunhupay.com/payment/query.html", options);
return post;
}
}
players club online casino d53qcb
You reported this effectively.gta online casino rigged red dog casino no deposit codes merkur online casinos
casinos online con visa online casino florida real money fastest payout online casino ontario
online casino software kaufen best online gambling apps hard rock online casino customer service phone number
belgische online casino's play in an ethereum casino ballys online casino app
ameristar casino online gambling omaha online poker blackjack counting cards online casino
fire kirin casino play online v45zni
Regards. An abundance of stuff.
where to report online casino top sports betting apps speaking rock casino online gambling
lcb online casino illinois casino online top ireland online casino sites
arizona online casino site nfl draft bets online casino progressive jackpots
most free spins online casino online casino california no deposit bonus is it illegal to play online casino in australia
mo online casino site new pa online casino real money bandar casino 368bet online
sports online casino r36dwy
Nicely put. Thank you.
como jugar en gran madrid casino online are online casinos safe az online casino real money no deposit
bandar betting ion casino online online casino in tennessee judi casino slot online
casino online no deposit real money busr sportsbook casina online
best rated online casinos casino online texas bedt nrw online casino
risk online casino best crypto casino usa parx casino online login
casino 21 online h149bf
Edithpab ??? 2024-11-3 06:26Regards. An abundance of stuff.
where to report online casino top sports betting apps speaking r ...
You actually suggested it well!
cat casino online esports betting sites buy online casino script
crazy slots online casino slotocash review sugarhouse online casino download
two up casino online new zealand online casino mich online casino
best betsoft online casinos best online poker app newest nj online casino
rush street online casino casino online arizona www royal casino online com
best australian online casino bonus f378ww
Many thanks. Terrific stuff.
best offshore online casinos ethereum casino yukon gold online casino canada
winstar casino games online california online casinos rivers casino online pa
us online casinos with free money best sports betting app reboot online casino
quick hit casino online slots tips and tricks betting websites instant payout online casinos
online casino oregon bet on boxing match online how to win casino online
royal planet casino online l698xv
Edithpab ??? 2024-11-3 21:00Many thanks. Terrific stuff.
best offshore online casinos ethereum casino yukon gold online casin ...
With thanks! I value this.
what states is online casino legal best casino games highest payout casino online
online casinos in alberta slotocash bonus no deposit nyc casino online
red cherry online casino best online casino pennsylvania casino ph online
online free casino world bingo boxing betting sites kickapoo casino online
online casino gaming companies betting on cricket best online casino canada real money
agen judi casino joker123 online v37wat
Beneficial write ups. Thanks a lot!
best online casinos netherlands online casino with no deposit bonus echtes online casino
online casinos in finland online casino new jersey sites real money online casinos for usa players
barstool online casino bonus play casino games for real money isle of capri online casino
does florida have online casino online super bowl betting online casino credit card deposit
online casino mit handy einzahlen slotocash free spins no deposit gta online casino heist release date
casino games online for real cash v87izf
Edithpab ??? 2024-11-3 05:46You reported this effectively.
gta online casino rigged red dog casino no deposit codes merkur onli ...
Cheers! Lots of advice!
el casino online slotocash no deposit bonus codes game vault casino online real money
free online casino no registration cash app gambling bandar judi casino sbc168 online
en que juego de casino online se gana mas dinero top crypto casinos online casinos japan
real online casino with real money best online casino georgia miami dice casino online
gta v online casino cheats golf betting online casino william hill
online casino michigan promotions s78hlz
Edithpab ??? 2024-11-3 05:46You reported this effectively.
gta online casino rigged red dog casino no deposit codes merkur onli ...
Very well spoken truly. .
slot v online casino nfl draft betting casino online romania bonus
casino online spania online casinos georgia az online casinos
best au online casinos free casino games new online casinos pa
online casinos like raging bull casino games online for real money online casino big wins
best online casino turkey real money blackjack online casino website online