一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - 微信支付java版本之查詢訂單

微信支付java版本之查詢訂單

2020-06-02 11:23wangxuewei111 JAVA教程

這篇文章主要為大家詳細(xì)介紹了微信支付java版本之查詢訂單,為大家分享了微信支付訂單的查詢接口,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信支付訂單的查詢接口,供大家參考,具體內(nèi)容如下

1.接口簡(jiǎn)介

微信支付java版本之查詢訂單

微信支付java版本之查詢訂單

微信支付java版本之查詢訂單

2.代碼實(shí)現(xiàn)
 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.zhrd.bussinss.platform.controller.shop;
 
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
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.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.zhrd.bussinss.platform.service.WeiXinPayService;
import com.zhrd.bussinss.platform.utils.CustomizedPropertyPlaceholderConfigurer;
import com.zhrd.bussinss.platform.weixinPayUtils.ClientCustomSSL;
 
@Controller
@RequestMapping("/shop/weiXinPayOrderSearch")
public class WeiXinPayOrderSearchController {
 
 
 @Autowired
 WeiXinPayService weiXinPayService;
 
 
 
 /**
 * 微信支出訂單狀態(tài)查詢
 * @param request
 * @param response
 * @return
 */
 @RequestMapping(value="/init",method=RequestMethod.GET )
 public String init(HttpServletRequest request,HttpServletResponse response){
 
 return "weixinPayOrderSearch";
 
 }
 
 
 /**
 * 微信支出訂單狀態(tài)查詢
 * @param request
 * @param response
 * @return
 */
 @RequestMapping(value="/getWeiXinPayOrder",method=RequestMethod.POST )
 @ResponseBody
 public Object getWeiXinPayOrder(HttpServletRequest request,HttpServletResponse response,@RequestParam(required=false) String transactionId,@RequestParam(required=false) String outTradeNo){
 try{
  
  KeyStore keyStore = KeyStore.getInstance("PKCS12");
  FileInputStream instream = new FileInputStream(new File(
   CustomizedPropertyPlaceholderConfigurer.getContextProperty("wx.cert").toString()));
  try {
  keyStore.load(instream, "見郵件".toCharArray());
  }finally {
  instream.close();
  }
 
  // Trust own CA and all self-signed certs
  SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore,
   "10061401".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/orderquery");
  Date dt = new Date();
  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  String nonceStr = sdf.format(dt).toString();<pre name="code" class="java">
  String xml = ClientCustomSSL.SearchNativePackage(transactionId.trim(),"", nonceStr);//此處為微信端id(本地id和服務(wù)器端id均可查詢)
  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());
   /*BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(entity.getContent()));
   String text;
   while ((text = bufferedReader.readLine()) != null) {
    System.out.println("======="+text);
   }*/
   
   
   SAXReader saxReader = new SAXReader();
   Document document = saxReader.read(entity.getContent());
   Element rootElt = document.getRootElement();
   System.out.println("根節(jié)點(diǎn):" + rootElt.getName());
   System.out.println("==="+rootElt.elementText("result_code"));
   System.out.println("==="+rootElt.elementText("return_msg"));
   String resultCode = rootElt.elementText("result_code");
   String returnCode = rootElt.elementText("return_code");
   JSONObject result = new JSONObject();
   System.out.println("resultCode====="+resultCode);
   System.out.println("returnCode====="+returnCode);
   System.out.println("trade_state====="+rootElt.elementText("trade_state"));
   System.out.println("transaction_id====="+rootElt.elementText("transaction_id"));
   System.out.println("out_trade_no====="+ rootElt.elementText("out_trade_no"));
   System.out.println("total_fee====="+rootElt.elementText("total_fee"));
   
   
   if(resultCode != null && resultCode.equals("SUCCESS") && returnCode.equals("SUCCESS")){
    result.put("tradeState", rootElt.elementText("trade_state"));
    result.put("transactionId", rootElt.elementText("transaction_id"));
    result.put("outTradeNo", rootElt.elementText("out_trade_no"));
    result.put("totalFee", rootElt.elementText("total_fee"));
    result.put("status","success");
    result.put("msg","success");
   }else if(returnCode.equals("SUCCESS")){
    result.put("errorCheck", "errCode");
    result.put("status","false");
    result.put("errorMsg",rootElt.elementText("err_code_des"));
   }else{
    result.put("errorCheck", "errMsg");
    result.put("status","false");
    result.put("errorMsg", rootElt.elementText("return_msg"));
   }
   return result;
 
   }
//   EntityUtils.consume(entity);
  }
  finally {
   responseEntry.close();
  }
  }
  finally {
  httpclient.close();
  }
  
  
 }catch(Exception e){
  e.printStackTrace();
  JSONObject result = new JSONObject();
  result.put("status","error");
  result.put("msg",e.getMessage());
  return result;
 }
 return "";
 
 
 }
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲国产欧美日韩在线一区 | 成人伊人青草久久综合网破解版 | 日本视频二区 | 色吧| 天天爽天天操 | 欧美成人aa久久狼窝动画 | 免费刷10000名片赞网站 | 亚洲天堂免费观看 | 国模娜娜一区二区三区 | yy6080久久国产伦理 | 国产午夜精品福利久久 | 星空无限传媒xk8129 | 欧美极品brazzers 高清 | 俄罗斯13一14处出血视频在线 | 俄罗斯妈妈k8影院在线观看 | 恩不要好大好硬好爽3p | 3d蒂法受辱在线播放 | 四虎最新永久在线精品免费 | 亚洲www在线 | 午夜视频一区二区 | 国产精品igao视频网网址 | 国产福利免费看 | 亚洲国产精品无码中文在线 | 男女全黄h全肉细节文 | 桃乃木香奈作品在线观看 | 美日韩一区二区三区 | 成年性香蕉漫画在线观看 | 亚洲四虎永久在线播放 | 日产乱码卡一卡2卡三卡四福利 | 北岛玲亚洲一区在线观看 | 亚欧有色在线观看免费版高清 | 欧美最新在线 | 黄www片 | 国产高清日韩 | 天天有好逼 | 国产成人精品高清免费 | 欧美洲大黑香蕉在线视频 | 闺蜜高h | 91制片厂 果冻传媒 天美传媒 | ak福利影院| 狠狠香蕉 |