E企盈营销工具技术服务商 热线:4006-838-530

慈利县E企盈小程序小程序微信退款

小程序微信退款老规矩写之前阅读官方文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_41、开发准备-下载证书1.1证书下载之后在本地是这样的选择.p12格式的文件放到配置文件的证书路径(SSLCERT_PATH)2、开发过程-配置文件此处的配置文件可以参考上篇文章小程序微信支付,其中SSLCERT_PATH(证书路径)和SSLCERT_PASSWORD(密码)就是所需的参数,路径直接填本地文件所在的路径即可(比如:C:/Users/Administrator/Downloads/WXCertUtil/cert/1521091331_20190114_cert/apiclient_cert.p12)#微信的配置参数APPID=微信公众平台中#开发者密码APPSECRET=微信公众平台中#微信商户号MCH_ID=客户开通的商户号#交易类型TRADE_TYPE=JSAPI(公众号和小程序都能用次类型)#微信退款回调地址#REFUND_NOTIFY_URL = 退款成功回调地址#签名方式SIGN_TYPE=MD5#微信支付商户密钥KEY=商户平台中下载证书的时候设置的密钥#证书路径SSLCERT_PATH = 证书路径#默认密码 默认为商户号SSLCERT_PASSWORD = 商户号

3、WXAuthUtil 参考上篇微信付款中的WXAuthUtil文件,其中SSLCERT_PATH、SSLCERT_PASSWORD、REFUND_NOTIFY_URL4、记重点!!!调用证书public class ClientCustomSSL { @SuppressWarnings("deprecation")    public static String doRefund(String url,String data) throws Exception { /** * 注意PKCS12证书 是从微信商户平台-》账户设置-》 API安全 中下载的 */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); /***此处要改*wxconfig.SSLCERT_PATH : 指向你的证书的绝对路径,带着证书去访问 ===========要修改*/FileInputStream instream = new FileInputStream(new File(WXAuthUtil.SSLCERT_PATH));//P12文件目录 try { /** * 此处要改 * * 下载证书时的密码、默认密码是你的MCHID mch_id===========要修改* */ keyStore.load(instream, WXAuthUtil.SSLCERT_PASSWORD.toCharArray());//这里写密码} finally { instream.close(); } /** * 此处要改 * 下载证书时的密码、默认密码是你的MCHID mch_id* */  SSLContext sslcontext = SSLContexts.custom() .loadKeyMaterial(keyStore, WXAuthUtil.SSLCERT_PASSWORD.toCharArray())//这里也是写密码的 .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf) .build(); try { HttpPost httpost = new HttpPost(url); // 设置响应头信开通内裤女小程序电话:4006-838-530息 httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpclient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } finally { httpclient.close(); } }

5、生成签名package mybatis.autocode.util;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.SortedMap;import mybatis.autocode.util.MD5Util;import tv.free.modules.wx.util.WXAuthUtil;/** * 生成签名(微信退款) * @author * */public class SignUtils {/** * @param characterEncoding 编码格式 utf-8 * */public static String creatSign(String characterEncoding,SortedMapObject, Object parameters) {StringBuffer sb = new StringBuffer();Set es = parameters.entrySet();Iterator it = es.iterator();while(it.hasNext()) {Map.Entry entry = (Map.Entry)it.next();String k = (String)entry.getKey();Object v = entry.getValue();if(null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {sb.append(k + "=" + v + "&");}}//商户号设置的api密钥sb.append("key=" + WXAuthUtil.KEY);String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase();System.out.println(sign);return sign;}}

接下来是退款代码接收返回参数的实体类public class RefundResult {private String result_code;private String return_msg;private String out_refund_no;private String refund_id;private String refund_fee;private String coupon_refund_fee;private String total_fee;private String cash_fee;private String err_code_des;public String getResult_code() {r开通本田小程序电话:4006-838-530eturn result_code;}public void setResult_code(String result_code) {this.result_code = result_code;}public String getReturn_msg() {return return_msg;}public void setReturn_msg(String return_msg) {this.return_msg = return_msg;}public String getOut_refund_no() {return out_refund_no;}public void setOut_refund_no(String out_refund_no) {this.out_refund_no = out_refund_no;}public String getRefund_id() {return refund_id;}public void setRefund_id(String refund_id) {this.refund_id = refund_id;}public String getRefund_fee() {return refund_fee;}public void setRefund_fee(String refund_fee) {this.refund_fee = refund_fee;}public Stri开通水草灯小程序电话:4006-838-530ng getCoupon_refund_fee() {return coupon_refund_fee;}public void setCoupon_refund_fee(String coupon_refund_fee) {this.coupon_refund_fee = coupon_refund_fee;}public String getTotal_fee() {return total_fee;}public void setTotal_fee(String total_fee) {this.total_fee = total_fee;}public String getCash_fee() {return cash_fee;}public void setCash_fee(String cash_fee) {this.cash_fee = cash_fee;}public String getErr_code_des() {return err_code_des;}public void setErr_code_des(String err_code_des) {this.err_code_des = err_code_des;}}

controller层/** * 微信退款 *  * @author yf * */@Controller@RequestMapping("/wx/refund")public class WXRefundController {/** * 申请退款 *  * @return * @param transactionId *            微信订单号 out_refund_no 退款单号 */public static String orderRefund() {SortedMapObject, Object packageParams = new TreeMapObject, Object();packageParams.put("appid", WXAuthUtil.APPID);packageParams.put("mch_id", WXAuthUtil.MCH_ID);String s = UUID.randomUUID().toString().replace("-", "");packageParams.put("nonc

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 慈利县E企盈小程序小程序微信退款
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏