微信退款接口
来源:互联网 发布:游戏美工设计师 编辑:程序博客网 时间:2024/04/28 18:42
private Object wxRefund(HttpServletRequest request, String id) throws Exception{
/*----- 1.生成预支付订单需要的的package数据-----*/
OrderMain orderMain = orderMainService.get(id);
int price=(new Double(orderMain.getTotalamount()*100)).intValue();
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
TreeMap paramMap = new TreeMap();
paramMap.put("appid", PaymentConst.WECHAT_APPID);
paramMap.put("mch_id", PaymentConst.WECHAT_MCHID);
paramMap.put("nonce_str", Util.getRandomString(30, null));
paramMap.put("op_user_id", PaymentConst.WECHAT_MCHID);
paramMap.put("out_trade_no", orderMain.getNumber());
paramMap.put("out_refund_no", orderMain.getNumber());
paramMap.put("total_fee",price);
paramMap.put("refund_fee", price);
/*----2.根据package生成签名sign---- */
paramMap.put("sign",Signature.createSign("UTF-8", paramMap));
System.out.println(Signature.createSign("UTF-8", paramMap));
/*----3.拼装需要提交到微信的数据xml---- */
/* try {
----4.读取证书文件,这一段是直接从微信支付平台提供的demo中copy的,所以一般不需要修改----
KeyStore keyStore = KeyStore.getInstance("PKCS12");
System.out.println("32158586586786875867754654643535465463");
FileInputStream instream = new FileInputStream(new File(PaymentConst.SSLCERT_PATH));
try {
System.out.println("32158586586786875867754654643535460");
keyStore.load(instream, PaymentConst.WECHAT_MCHID.toCharArray());
}catch(Exception e){
System.out.println("32158586586786875867754654643535465461");
e.printStackTrace();
}
finally {
instream.close();
}
System.out.println("32158586586786875867754654643535465462");
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, PaymentConst.WECHAT_MCHID.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();
System.out.println("32158586586786875867754654643535465463");*/
/*----5.发送数据到微信的退款接口---- */
String url="https://api.mch.weixin.qq.com/secapi/pay/refund";
String response = HttpClientUtil.executeBySslPost(url,new String( XMLUtils.simpleMapToXml(paramMap).getBytes(), "UTF-8"));
System.out.println("预支付返回结果:"+response);
Map<String, String> resultParams = getWechatXmlToMap(response);
// logger.info(jsonStr);
if (PaymentConst.WECHAT_STATUSCODE_FAIL.equals(resultParams.get("return_code"))){
throw new MessageException(resultParams.get("return_msg"));
}else{
if (PaymentConst.WECHAT_STATUSCODE_FAIL.equals(resultParams.get("result_code"))){
throw new MessageException(resultParams.get("return_msg"));
}
}
/* }catch (Exception e) {
}*/
return result;
}
/*----- 1.生成预支付订单需要的的package数据-----*/
OrderMain orderMain = orderMainService.get(id);
int price=(new Double(orderMain.getTotalamount()*100)).intValue();
Result<Map<String, Object>> result = new Result<Map<String, Object>>();
TreeMap paramMap = new TreeMap();
paramMap.put("appid", PaymentConst.WECHAT_APPID);
paramMap.put("mch_id", PaymentConst.WECHAT_MCHID);
paramMap.put("nonce_str", Util.getRandomString(30, null));
paramMap.put("op_user_id", PaymentConst.WECHAT_MCHID);
paramMap.put("out_trade_no", orderMain.getNumber());
paramMap.put("out_refund_no", orderMain.getNumber());
paramMap.put("total_fee",price);
paramMap.put("refund_fee", price);
/*----2.根据package生成签名sign---- */
paramMap.put("sign",Signature.createSign("UTF-8", paramMap));
System.out.println(Signature.createSign("UTF-8", paramMap));
/*----3.拼装需要提交到微信的数据xml---- */
/* try {
----4.读取证书文件,这一段是直接从微信支付平台提供的demo中copy的,所以一般不需要修改----
KeyStore keyStore = KeyStore.getInstance("PKCS12");
System.out.println("32158586586786875867754654643535465463");
FileInputStream instream = new FileInputStream(new File(PaymentConst.SSLCERT_PATH));
try {
System.out.println("32158586586786875867754654643535460");
keyStore.load(instream, PaymentConst.WECHAT_MCHID.toCharArray());
}catch(Exception e){
System.out.println("32158586586786875867754654643535465461");
e.printStackTrace();
}
finally {
instream.close();
}
System.out.println("32158586586786875867754654643535465462");
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, PaymentConst.WECHAT_MCHID.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();
System.out.println("32158586586786875867754654643535465463");*/
/*----5.发送数据到微信的退款接口---- */
String url="https://api.mch.weixin.qq.com/secapi/pay/refund";
String response = HttpClientUtil.executeBySslPost(url,new String( XMLUtils.simpleMapToXml(paramMap).getBytes(), "UTF-8"));
System.out.println("预支付返回结果:"+response);
Map<String, String> resultParams = getWechatXmlToMap(response);
// logger.info(jsonStr);
if (PaymentConst.WECHAT_STATUSCODE_FAIL.equals(resultParams.get("return_code"))){
throw new MessageException(resultParams.get("return_msg"));
}else{
if (PaymentConst.WECHAT_STATUSCODE_FAIL.equals(resultParams.get("result_code"))){
throw new MessageException(resultParams.get("return_msg"));
}
}
/* }catch (Exception e) {
}*/
return result;
}
阅读全文
0 0
- 微信退款接口
- 微信退款接口
- 微信支付退款接口
- 微信支付退款接口
- 微信支付接口 退款接口
- 10.PHP接入微信退款接口
- app微信退款接口Java 后台
- 微信申请退款接口及调用模板消息接口
- 微信退款和支付宝退款接口调用(java版)
- 微信退款和支付宝退款接口调用(java版)
- 微信退款和支付宝退款接口调用(java版)
- java 微信与支付宝退款接口开发总结
- 关于微信支付退款接口问题 PHP版
- 关于微信支付退款接口问题 PHP版
- 微信退款
- 微信退款
- 微信退款
- 微信退款问题
- 社交系统ThinkSNS V4更新播报
- php文件大文件上传
- neural networks deep learning Building your deep neural network: Step by Step参考答案
- 得到当前月份所有的周一至周五
- php跨域问题,ajax发送的header自定义问题
- 微信退款接口
- Scala程序设计-Evaluation Strategy
- 文件下载功能在苹果手机中的特殊处理
- mongodb crud 之 insert
- 观察者模式
- 用insert 插入一个带&的字符串时总是让输入值
- [PAT]1012. The Best Rank (25)@Java
- [HDU](3746)Cyclic Nacklace ---KMP(串)
- 细聊分布式ID生成方法