//XmlUtil.xmlToMap(s)
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>
//引用的包
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.http.ssl.SSLContexts;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.URI;
import java.security.KeyStore;
import java.util.*;
//前端调起支付接口
public Map<String, String> createMiniProgramTradePayAndcallPay(String orderId,long payAmont,String openId) throws Exception {
String nonceStr = getRandomString(32);
String timestamp = String.valueOf(new Date().getTime() / 1000);//时间以秒为单位
Map<String, String> data = new HashMap<String, String>();
data.put("appid", "wx0123abcdefghigkl");//18位appid
data.put("mch_id", "0123456789");//10位mchid
data.put("nonce_str", nonceStr);//随机32位数字字母
data.put("sign_type", "MD5");
data.put("body", "test");
data.put("out_trade_no", orderId);//商户订单id
data.put("total_fee", String.valueOf(payAmont));//订单金额单位为分 String
data.put("spbill_create_ip", "123.123.123.11");//支持IPV4和IPV6两种格式的IP地址。调用微信支付API的机器IP 终端IP 公司公网ip
data.put("notify_url", "www.baidu.com");//异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。
//公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http。
微信小程序(支付、退款)v2版本(java)
最新推荐文章于 2022-11-09 16:16:47 发布
本文详细介绍了如何使用Java后台实现微信小程序的支付与退款功能,涵盖了调用微信支付API的关键步骤,包括签名生成、请求处理及错误处理等核心流程。
摘要由CSDN通过智能技术生成