微信撤销订单java,微信支付java版本之关闭订单

package com.zhrd.bussinss.platform.utils;

import java.io.File;

import java.io.FileInputStream;

import java.security.KeyStore;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.net.ssl.SSLContext;

import net.sf.json.JSONObject;

import org.apache.http.HttpEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.conn.ssl.SSLConnectionSocketFactory;

import org.apache.http.conn.ssl.SSLContexts;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.util.EntityUtils;

import org.dom4j.Document;

import org.dom4j.Element;

import org.dom4j.io.SAXReader;

import org.springframework.transaction.annotation.Transactional;

import com.zhrd.bussinss.platform.weixinPayUtils.ClientCustomSSL;

@Transactional

public class CloseWeiXinOrderUtils {

public static Object closeWeiXinOrder(String outTradeNo) {

try{

KeyStore keyStore = KeyStore.getInstance("PKCS12");

FileInputStream instream = new FileInputStream(new File(

CustomizedPropertyPlaceholderConfigurer.getContextProperty("wx.cert").toString()));

try {

keyStore.load(instream, "10061401".toCharArray());

}finally {

instream.close();

}

// Trust own CA and all self-signed certs

SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,

"见邮件".toCharArray()).build();

// Allow TLSv1 protocol only

SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(

sslcontext, new String[] { "TLSv1" }, null,

SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

CloseableHttpClient httpclient = HttpClients.custom()

.setSSLSocketFactory(sslsf).build();

// HttpGet httpget = new

// HttpGet("https://api.mch.weixin.qq.com/secapi/pay/refund");

HttpPost httppost = new HttpPost(

"https://api.mch.weixin.qq.com/pay/closeorder");

Date dt = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

String nonceStr = sdf.format(dt).toString();

String xml = ClientCustomSSL.CreateCloseOrder(outTradeNo,nonceStr);

try {

StringEntity se = new StringEntity(xml);

httppost.setEntity(se);

System.out.println("executing request" + httppost.getRequestLine());

CloseableHttpResponse responseEntry = httpclient.execute(httppost);

try {

HttpEntity entity = responseEntry.getEntity();

System.out.println("----------------------------------------");

System.out.println(responseEntry.getStatusLine());

if (entity != null) {

System.out.println("Response content length: "

+ entity.getContentLength());

SAXReader saxReader = new SAXReader();

Document document = saxReader.read(entity.getContent());

Element rootElt = document.getRootElement();

String resultCode = rootElt.elementText("result_code");

String returnCode = rootElt.elementText("return_code");

System.out.println("resultCode----"+resultCode);

System.out.println("returnCode---"+returnCode);

JSONObject result = new JSONObject();

if(returnCode.equals("SUCCESS")){

if(resultCode.equals("SUCCESS")){

result.put("status","success");

result.put("msg","success");

}else{

result.put("status","false");

result.put("msg",rootElt.elementText("err_code_des"));

}

}else{

result.put("status","false");

result.put("msg",rootElt.elementText("return_msg"));

}

return result;

}

EntityUtils.consume(entity);

}

finally {

responseEntry.close();

}

}

finally {

httpclient.close();

}

return null;

}catch(Exception e){

e.printStackTrace();

JSONObject result = new JSONObject();

result.put("status","error");

result.put("msg",e.getMessage());

return result;

}

}

}

3.其他接口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值