国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

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

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - java實(shí)現(xiàn)網(wǎng)站微信掃碼支付

java實(shí)現(xiàn)網(wǎng)站微信掃碼支付

2021-05-17 15:10獵狐尊者 Java教程

這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)網(wǎng)站微信掃碼支付,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、網(wǎng)站微信掃碼支付開發(fā)并沒有現(xiàn)成的java示例,總結(jié)一下自己微信掃碼支付心得

二、首先去微信公眾平臺(tái)申請賬戶

https://mp.weixin.qq.com 
**

三、賬戶開通、開發(fā)者認(rèn)證之后就可以進(jìn)行微信支付開發(fā)了

1、微信統(tǒng)一下單接口調(diào)用獲取預(yù)支付id,以及生成二維碼所需的codeurl

?
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
/**
 * 保存訂單,并生成二維碼所需的codeurl
 *
 * @param request
 * @param response
 * @param notifyurlbuf
 * @param order
 * @return
 * @throws exception
 */
 @override
 public map<string, string> getwechatorderinfo(string ip, cuser user, string notifyurl, order order) throws exception {
 map<string, string> resultmap = new hashmap<string, string>();
 // 生成并保存訂單
 order.setuserid(user.getid());
 // 支付方式 0:銀聯(lián) 1:支付寶 2:網(wǎng)上銀行 3:微信 4:其他
 order.setpaytype("3");
 // 生成訂單號(hào)
 order.setorderno(ordernogenerator.getorderno());
 // 訂單類型 1:消費(fèi) 2:退款
 order.setordertype("1");
 // 訂單創(chuàng)建時(shí)間
 order.setcreatetime(new date());
 // 訂單更新時(shí)間
 order.setupdatetime(new date());
 // 訂單狀態(tài) 0: 交易中 1:完成 2:已取消
 order.setorderstatus("0");
 // 付款狀態(tài) 0:失敗 1:成功 2、待付款
 order.setpaystatus("2");
 // 設(shè)置訂單失效時(shí)間
 calendar calendar = calendar.getinstance();
 calendar.add(calendar.hour, 2);
 order.setexpiretime(calendar.gettime());
 integer orderid = this.balancedao.saveorder(order);
 
 map<string, string> paypreidmap = new hashmap<>();
 paypreidmap = wechatutil.getpaypreid(string.valueof(orderid), "體檢報(bào)告", notifyurl, ip,
  string.valueof((order.getmoney().multiply(new bigdecimal(100)).intvalue())), orderid.tostring());
 string prepayid = paypreidmap.get("prepay_id");
 // 更新
 order.setid(orderid);
 order.setprepayid(prepayid);
 order.setcodeurl(paypreidmap.get("code_url"));
 this.balancedao.updateorder(order);
 // return wechatutil.qrfromgoogle(order.getcodeurl(), 300, 0);
 resultmap.put("codeurl", order.getcodeurl());
 resultmap.put("orderid", string.valueof(order.getid()));
 return resultmap;
 }

此方法返回的數(shù)據(jù)如下

?
1
2
3
4
5
6
7
8
9
10
11
<xml><return_code><![cdata[success]]></return_code>
<return_msg><![cdata[ok]]></return_msg>
<appid><![cdata[wxaf0b*****8afbf]]></appid>
<mch_id><![cdata[1408****02]]></mch_id>
<nonce_str><![cdata[zf0vgvdtvycbliwb]]></nonce_str>
<sign><![cdata[a2910f16086211153d747058063b3368]]></sign>
<result_code><![cdata[success]]></result_code>
<prepay_id><![cdata[wx201701191109388037e9a12310276591827]]></prepay_id>
<trade_type><![cdata[native]]></trade_type>
<code_url><![cdata[weixin://wxpay/bizpayurl?pr=1ujornx]]></code_url>
</xml>

2、服務(wù)器端接受微信支付結(jié)果通知

?
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
/**
  * 保存微信通知結(jié)果
  *
  * @param request
  * @param response
  * @return
  * @throws exception
  */
 @override
 public string savewechatnotify(string notifyinfoxml) throws exception {
  map<string, string> noticemap = xmlutil.doxmlparse(notifyinfoxml);
  // 這個(gè)其實(shí)是訂單 的id
  string outtradeno = noticemap.get("out_trade_no");
  order order = this.balancedao.getorderbyid(integer.valueof(outtradeno));
  // 如果支付通知信息不為,說明請求已經(jīng)處理過,直接返回
  if (stringutil.isnotempty(order.getnotifyinfo())) {
   return "success";
  }
  string sign = noticemap.get("sign");
  noticemap.remove("sign");
  // 驗(yàn)簽通過
  if (wechatutil.getsignveryfy(noticemap, sign)) {
   // 通信成功此字段是通信標(biāo)識(shí),非交易標(biāo)識(shí),交易是否成功需要查看result_code來判斷
   if ("success".equals(noticemap.get("return_code"))) {
    // 交易成功
    if ("success".equals(noticemap.get("result_code"))) {
     // 商戶訂單號(hào)
 
     // 訂單更新時(shí)間
     order.setupdatetime(new date());
     // ------------------------------
     // 處理業(yè)務(wù)開始
     // ------------------------------
     // 是否交易成功,1:成功0:失敗
     // 微信支付成功
     order.setpaystatus("1");
     // 訂單狀態(tài) 0: 交易中 1:完成 2:已取消
     order.setorderstatus("1");
     // 保存通知信息
     order.setnotifyinfo(notifyinfoxml);
     this.balancedao.updateorder(order);
     // 處理業(yè)務(wù)完畢
    } else {
     // 錯(cuò)誤時(shí),返回結(jié)果未簽名,記錄retcode、retmsg看失敗詳情。
     logger.info("查詢驗(yàn)證簽名失敗或業(yè)務(wù)錯(cuò)誤");
     logger.info("retcode:" + noticemap.get("retcode") + " retmsg:" + noticemap.get("retmsg"));
    }
    return "success";
   } else {
    logger.info("后臺(tái)調(diào)用通信失敗");
   }
   return "success";
  } else {
   logger.info("通知簽名驗(yàn)證失敗");
  }
  return null;
 }

3、上面代碼用到的工具方法都在wechatutil.java工具類中

?
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package com.caifu.tencent.common;
 
import java.io.ioexception;
import java.net.urisyntaxexception;
import java.net.urlencoder;
import java.util.arraylist;
import java.util.collections;
import java.util.hashmap;
import java.util.linkedlist;
import java.util.list;
import java.util.map;
import java.util.random;
 
import org.apache.commons.httpclient.httpstatus;
import org.apache.http.namevaluepair;
import org.apache.http.client.config.requestconfig;
import org.apache.http.client.methods.closeablehttpresponse;
import org.apache.http.client.methods.httppost;
import org.apache.http.client.utils.uribuilder;
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.jdom2.jdomexception;
import org.slf4j.logger;
import org.slf4j.loggerfactory;
 
import com.caifu.login.utils.xmlutil;
 
public class wechatutil {
 
 private static logger logger = loggerfactory.getlogger(wechatutil.class);
 public static final string tag = "wechat.util";
 private static final int timeout = 5000;
 
 public static byte[] httppost(string url, string entity) throws urisyntaxexception, ioexception {
  if (url == null || url.length() == 0) {
   logger.info(tag, "httppost, url is null");
   return null;
  }
  closeablehttpclient httpclient = httpclients.createdefault();
  uribuilder uribuilder = new uribuilder(url);
  httppost httppost = new httppost(uribuilder.build());
  requestconfig requestconfig = requestconfig.custom().setsockettimeout(timeout).setconnectionrequesttimeout(timeout).setconnecttimeout(timeout).build();
  httppost.setconfig(requestconfig);
  // 避免漢字亂碼導(dǎo)致請求失敗,
  httppost.setentity(new stringentity(entity, "utf-8"));
  closeablehttpresponse resp = null;
  try {
   resp = httpclient.execute(httppost);
   if (resp.getstatusline().getstatuscode() != httpstatus.sc_ok) {
    logger.info(tag, "httpget fail, status code = " + resp.getstatusline().getstatuscode());
    return null;
   }
   return entityutils.tobytearray(resp.getentity());
  } catch (exception e) {
   logger.info(tag, "httppost exception, e = " + e.getmessage());
   e.printstacktrace();
   return null;
  } finally {
   if (httpclient != null) {
    httpclient.close();
   }
   if (resp != null) {
    resp.close();
   }
  }
 }
 
 /**
  * 把數(shù)組所有元素排序,并按照“參數(shù)=參數(shù)值”的模式用“&”字符拼接成字符串
  *
  * @param params
  *   需要排序并參與字符拼接的參數(shù)組
  * @return 拼接后字符串
  */
 public static string createlinkstring(map<string, string> params) {
 
  list<string> keys = new arraylist<string>(params.keyset());
  collections.sort(keys);
 
  string prestr = "";
 
  for (int i = 0; i < keys.size(); i++) {
   string key = keys.get(i);
   string value = params.get(key);
 
   if (i == keys.size() - 1) {// 拼接時(shí),不包括最后一個(gè)&字符
    prestr = prestr + key + "=" + value;
   } else {
    prestr = prestr + key + "=" + value + "&";
   }
  }
 
  return prestr;
 }
 
 /**
  * 根據(jù)反饋回來的信息,生成簽名結(jié)果
  *
  * @param params
  *   通知返回來的參數(shù)數(shù)組
  * @param sign
  *   比對的簽名結(jié)果
  * @return 生成的簽名結(jié)果
  */
 public static boolean getsignveryfy(map<string, string> params, string sign) {
  // 過濾空值、sign與sign_type參數(shù)
  // map<string, string> sparanew = alipaycore.parafilter(params);
  // 獲取待簽名字符串
  string presignstr = createlinkstring(params);
  presignstr += "&key=" + configure.getkey();
  // 獲得簽名驗(yàn)證結(jié)果
  string resultsign = md5.md5encode(presignstr).touppercase();
  // string resultsign = md5util.md5encode(presignstr.tostring(),
  // "utf-8").tolowercase();
  if (sign.equals(resultsign)) {
   return true;
  } else {
   return false;
  }
 }
 
 /**
  * 裝配xml,生成請求prepayid所需參數(shù)
  *
  * @param params
  * @return
  */
 public static string toxml(list<namevaluepair> params) {
  stringbuilder sb = new stringbuilder();
  sb.append("<xml>");
  for (int i = 0; i < params.size(); i++) {
   sb.append("<" + params.get(i).getname() + ">");
   sb.append(params.get(i).getvalue());
   sb.append("</" + params.get(i).getname() + ">");
  }
  sb.append("</xml>");
  return sb.tostring();
 }
 
 /**
  * 生成簽名
  */
 public static string genpackagesign(list<namevaluepair> params) {
  stringbuilder sb = new stringbuilder();
  for (int i = 0; i < params.size(); i++) {
   sb.append(params.get(i).getname());
   sb.append('=');
   sb.append(params.get(i).getvalue());
   sb.append('&');
  }
  sb.append("key=");
  sb.append(configure.getkey());
  string packagesign = md5.md5encode(sb.tostring());
  return packagesign;
 }
 
 /**
  *
  * @param goodorderno
  * @param body
  * @param noticeurl
  * @param ip
  * @param totalfee
  * @return
  */
 public static string genproductargs(string goodorderno, string body, string noticeurl, string ip, string totalfee, string productid) {
  stringbuffer xml = new stringbuffer();
  try {
   string noncestr = getnoncestr();
   xml.append("</xml>");
   list<namevaluepair> packageparams = new linkedlist<namevaluepair>();
   packageparams.add(new basicnamevaluepair("appid", configure.getappid()));
   packageparams.add(new basicnamevaluepair("body", body));
   packageparams.add(new basicnamevaluepair("mch_id", configure.getmchid()));
   packageparams.add(new basicnamevaluepair("nonce_str", noncestr));
   packageparams.add(new basicnamevaluepair("notify_url", noticeurl));
   packageparams.add(new basicnamevaluepair("out_trade_no", goodorderno));
   packageparams.add(new basicnamevaluepair("product_id", productid));
   packageparams.add(new basicnamevaluepair("spbill_create_ip", ip));
   packageparams.add(new basicnamevaluepair("total_fee", totalfee));
   packageparams.add(new basicnamevaluepair("trade_type", "native"));
   string sign = genpackagesign(packageparams);
   packageparams.add(new basicnamevaluepair("sign", sign));
   string xmlstring = toxml(packageparams);
   return xmlstring;
  } catch (exception e) {
   logger.info("genproductargs fail, ex = " + e.getmessage());
   return null;
  }
 }
 
 /**
  * 生成支付簽名
  *
  * @param params
  * @return
  */
 public static string genappsign(list<namevaluepair> params) {
  stringbuilder sb = new stringbuilder();
  for (int i = 0; i < params.size(); i++) {
   sb.append(params.get(i).getname());
   sb.append('=');
   sb.append(params.get(i).getvalue());
   sb.append('&');
  }
  sb.append("key=");
  sb.append(configure.getkey());
  string appsign = md5.md5encode(sb.tostring()).touppercase();
  logger.info("orion", appsign);
  return appsign;
 }
 
 /**
  * 生成調(diào)用微信支付所需參數(shù)
  *
  * @param prepayid
  * @return
  */
 public static map<string, string> genpayreq(string prepayid) {
  map<string, string> resultmap = new hashmap<string, string>();
  string timestamp = gettimestamp();
  string noncestr = getnoncestr();
  list<namevaluepair> signparams = new linkedlist<namevaluepair>();
  signparams.add(new basicnamevaluepair("appid", configure.getappid()));
  signparams.add(new basicnamevaluepair("noncestr", noncestr));
  signparams.add(new basicnamevaluepair("package", "sign=wxpay"));
  signparams.add(new basicnamevaluepair("partnerid", configure.getmchid()));
  signparams.add(new basicnamevaluepair("prepayid", prepayid));
  signparams.add(new basicnamevaluepair("timestamp", timestamp));
  string sign = genappsign(signparams);
  resultmap.put("appid", configure.getappid());
  resultmap.put("noncestr", noncestr);
  resultmap.put("packagevalue", "sign=wxpay");
  resultmap.put("partnerid", configure.getmchid());
  resultmap.put("prepayid", prepayid);
  resultmap.put("timestamp", timestamp);
  resultmap.put("sign", sign);
  return resultmap;
 }
 
 /**
  * 微信支付生成預(yù)支付訂單
  *
  * @throws ioexception
  * @throws jdomexception
  */
 public static map<string, string> getpaypreid(string goodorderno, string body, string noticeurl, string ip, string totalfee, string productid) throws exception {
  string paramsxml = genproductargs(goodorderno, body, noticeurl, ip, totalfee, productid);
  logger.info("orion", paramsxml);
  byte[] buf = wechatutil.httppost(configure.unifiedorder_api, paramsxml);
  string contentxml = new string(buf);
  map<string, string> resultmap = xmlutil.doxmlparse(contentxml);
  return resultmap;
 }
 
 public static string getnoncestr() {
  random random = new random();
  return md5.md5encode(string.valueof(random.nextint(10000)));
 }
 
 public static string gettimestamp() {
  return string.valueof(system.currenttimemillis() / 1000);
 }
 
 /**
  * 生成支付二維碼
  * @param request
  * @param response
  * @param width
  * @param height
  * @param text 微信生成預(yù)定id時(shí),返回的codeurl
  */
 public static void getqrcode(httpservletrequest request, httpservletresponse response, integer width, integer height, string text) {
  if (width == null) {
   width = 300;
  }
  if (height == null) {
   height = 300;
  }
  string format = "jpg";
  hashtable hints = new hashtable();
  hints.put(encodehinttype.character_set, "utf-8");
  bitmatrix bitmatrix;
  try {
   bitmatrix = new multiformatwriter().encode(text, barcodeformat.qr_code, width, height, hints);
   matrixtoimagewriter.writetostream(bitmatrix, format, response.getoutputstream());
  } catch (writerexception e) {
   e.printstacktrace();
  } catch (ioexception e) {
   // todo auto-generated catch block
   e.printstacktrace();
  }
 }
}

生成二維碼需要兩jar

?
1
2
3
4
5
6
7
8
9
10
11
12
<!-- google zxing 二維碼jar begin -->
  <dependency>
   <groupid>com.google.zxing</groupid>
   <artifactid>core</artifactid>
   <version>3.3.0</version>
  </dependency>
  <dependency>
   <groupid>com.google.zxing</groupid>
   <artifactid>javase</artifactid>
   <version>3.3.0</version>
  </dependency>
<!-- google zxing 二維碼jar begin -->

4、下面是用到的配置類

?
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
package com.caifu.tencent.common;
 
/**
 * user: rizenguo
 * date: 2014/10/29
 * time: 14:40
 * 這里放置各種配置數(shù)據(jù)
 */
public class configure {
//這個(gè)就是自己要保管好的私有key了(切記只能放在自己的后臺(tái)代碼里,不能放在任何可能被看到源代碼的客戶端程序中)
 // 每次自己post數(shù)據(jù)給api的時(shí)候都要用這個(gè)key來對所有字段進(jìn)行簽名,生成的簽名會(huì)放在sign這個(gè)字段,api收到post數(shù)據(jù)的時(shí)候也會(huì)用同樣的簽名算法對post過來的數(shù)據(jù)進(jìn)行簽名和驗(yàn)證
 // 收到api的返回的時(shí)候也要用這個(gè)key來對返回的數(shù)據(jù)算下簽名,跟api的sign數(shù)據(jù)進(jìn)行比較,如果值不一致,有可能數(shù)據(jù)被第三方給篡改
 
 private static string key = "a6gb0dy4dsfdssupcpsdfdshkscdqcr3exs";
 
 
 private static string appsecret="7584sdfdsfe4f26fadsfsdfs56f10728a";
 
 //微信分配的公眾號(hào)id(開通公眾號(hào)之后可以獲取到)
 private static string appid = "wxaf0b86sdfsdf8afbf";
 
 //微信支付分配的商戶號(hào)id(開通公眾號(hào)的微信支付功能之后可以獲取到)
 private static string mchid = "14012313702";
 
 //受理模式下給子商戶分配的子商戶號(hào)
 private static string submchid = "";
 
 //https證書的本地路徑
 private static string certlocalpath = "";
 
 //https證書密碼,默認(rèn)密碼等于商戶號(hào)mchid
 private static string certpassword = "";
 
 //是否使用異步線程的方式來上報(bào)api測速,默認(rèn)為異步模式
 private static boolean usethreadtodoreport = true;
 
 //機(jī)器ip
 private static string ip = "";
 
 //以下是幾個(gè)api的路徑:
 //1)被掃支付api
 public static string unifiedorder_api = "https://api.mch.weixin.qq.com/pay/unifiedorder";
 
 public static string pay_api = "https://api.mch.weixin.qq.com/pay/micropay";
 
 //2)被掃支付查詢api
 public static string pay_query_api = "https://api.mch.weixin.qq.d/pay/orderquery";
 
 //3)退款api
 public static string refund_api = "https://api.mch.weixin.qq.com/secapi/pay/refund";
 
 //4)退款查詢api
 public static string refund_query_api = "https://api.mch.weixin.qq.com/pay/refundquery";
 
 //5)撤銷api
 public static string reverse_api = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
 
 //6)下載對賬單api
 public static string download_bill_api = "https://api.mch.weixin.qq.com/pay/downloadbill";
 
 //7) 統(tǒng)計(jì)上報(bào)api
 public static string report_api = "https://api.mch.weixin.qq.com/payitil/report";
 
 public static boolean isusethreadtodoreport() {
  return usethreadtodoreport;
 }
 
 public static void setusethreadtodoreport(boolean usethreadtodoreport) {
  configure.usethreadtodoreport = usethreadtodoreport;
 }
 
 public static string httpsrequestclassname = "com.tencent.common.httpsrequest";
 
 public static void setkey(string key) {
  configure.key = key;
 }
 
 public static void setappid(string appid) {
  configure.appid = appid;
 }
 
 public static void setmchid(string mchid) {
  configure.mchid = mchid;
 }
 
 public static void setsubmchid(string submchid) {
  configure.submchid = submchid;
 }
 
 public static void setcertlocalpath(string certlocalpath) {
  configure.certlocalpath = certlocalpath;
 }
 
 public static void setcertpassword(string certpassword) {
  configure.certpassword = certpassword;
 }
 
 public static void setip(string ip) {
  configure.ip = ip;
 }
 
 public static string getkey(){
  return key;
 }
 
 public static string getappid(){
  return appid;
 }
 
 public static string getmchid(){
  return mchid;
 }
 
 public static string getsubmchid(){
  return submchid;
 }
 
 public static string getcertlocalpath(){
  return certlocalpath;
 }
 
 public static string getcertpassword(){
  return certpassword;
 }
 
 public static string getip(){
  return ip;
 }
 
 public static void sethttpsrequestclassname(string name){
  httpsrequestclassname = name;
 }
 
}

在這里需要注意的配置
private static string key = “a6gb0dy4dsfdssupcpsdfdshkscdqcr3exs”;
這里的key 是登陸 https://pay.weixin.qq.com/index.php/core/info  (微信商戶平臺(tái))設(shè)置的api_key

5、xml 解析工具類

?
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
package com.caifu.login.utils;
 
import java.io.bytearrayinputstream;
import java.io.ioexception;
import java.io.inputstream;
import java.util.hashmap;
import java.util.iterator;
import java.util.list;
import java.util.map;
 
import javax.servlet.http.httpservletrequest;
 
import org.dom4j.io.saxreader;
import org.jdom2.document;
import org.jdom2.element;
import org.jdom2.jdomexception;
import org.jdom2.input.saxbuilder;
 
/**
 * xml工具類
 *
 * @author miklchen
 *
 */
public class xmlutil {
 
 /**
  * 解析xml,返回第一級(jí)元素鍵值對。如果第一級(jí)元素有子節(jié)點(diǎn),則此節(jié)點(diǎn)的值是子節(jié)點(diǎn)的xml數(shù)據(jù)。
  *
  * @param strxml
  * @return
  * @throws jdomexception
  * @throws ioexception
  */
 public static map doxmlparse(string strxml) throws jdomexception, ioexception {
  strxml = strxml.replacefirst("encoding=\".*\"", "encoding=\"utf-8\"");
 
  if (null == strxml || "".equals(strxml)) {
   return null;
  }
 
  map m = new hashmap();
 
  inputstream in = new bytearrayinputstream(strxml.getbytes("utf-8"));
  saxbuilder builder = new saxbuilder();
  document doc = builder.build(in);
  element root = doc.getrootelement();
  list list = root.getchildren();
  iterator it = list.iterator();
  while (it.hasnext()) {
   element e = (element) it.next();
   string k = e.getname();
   string v = "";
   list children = e.getchildren();
   if (children.isempty()) {
    v = e.gettextnormalize();
   } else {
    v = xmlutil.getchildrentext(children);
   }
 
   m.put(k, v);
  }
 
  // 關(guān)閉流
  in.close();
 
  return m;
 }
 
 /**
  * 獲取子結(jié)點(diǎn)的xml
  *
  * @param children
  * @return string
  */
 public static string getchildrentext(list children) {
  stringbuffer sb = new stringbuffer();
  if (!children.isempty()) {
   iterator it = children.iterator();
   while (it.hasnext()) {
    element e = (element) it.next();
    string name = e.getname();
    string value = e.gettextnormalize();
    list list = e.getchildren();
    sb.append("<" + name + ">");
    if (!list.isempty()) {
     sb.append(xmlutil.getchildrentext(list));
    }
    sb.append(value);
    sb.append("</" + name + ">");
   }
  }
 
  return sb.tostring();
 }
 
 /**
  * 將requestxml通知結(jié)果轉(zhuǎn)出啊成map
  * @param request
  * @return
  * @throws exception
  */
 public static map<string, string> parsexml(httpservletrequest request) throws exception {
  // 解析結(jié)果存儲(chǔ)在hashmap
  map<string, string> map = new hashmap<string, string>();
  inputstream inputstream = request.getinputstream();
  // 讀取輸入流
  saxreader reader = new saxreader();
  org.dom4j.document document = reader.read(inputstream);
  // 得到xml根元素
  org.dom4j.element root = document.getrootelement();
  // 得到根元素的所有子節(jié)點(diǎn)
  list<org.dom4j.element> elementlist = root.elements();
  // 遍歷所有子節(jié)點(diǎn)
  for (org.dom4j.element e : elementlist)
   map.put(e.getname(), e.gettext());
  // 釋放資源
  inputstream.close();
  inputstream = null;
  return map;
 }
 
}

6、整個(gè)后臺(tái)服務(wù)已經(jīng)完成,最后關(guān)閉頁面微信支付二維碼,告知用戶支付已經(jīng)完成了

?
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
var f;
 /* 定時(shí)任務(wù)方法,異步請求去查詢訂單是否支付*/
 function getorder() {
  var orderid = $('#orderid').val();
  if (orderid != '') {
   $.ajax({
    url : "${base}/balance/auth/ispay?orderid=" + orderid,
    type : "get",
    async : false,
    success : function(d) {
     if (d == "1") {
      //當(dāng)獲取到微信支付結(jié)果時(shí),關(guān)閉二維碼div
      $(".weixinpay").css("display", "none");
      $("#zhichutankuang").css("display", "block");
      ////當(dāng)獲取到微信支付結(jié)果時(shí),關(guān)閉定時(shí)任務(wù)
      clearinterval(f);
      // layer.alert('付款成功', {
      // skin : 'layui-layer-molv', // 樣式類名
      // closebtn : 0
      // }, function() {
      // location.href = "${base}/balance/auth/presentation?tjno=" + $("#tjno").val();
      // });
 
     }
    }
   });
  }
 }
 //異步請求獲取生成二維碼的url
 $(".paylast").click(function() {
  var $paytype = $('input:radio:checked').val();
  var $money = $("#money").val();
  var $tjreporttype = $("#tjreporttype").val();
  var $tjno = $("#tjno").val();
  $.ajax({
   url : "${base}/balance/auth/wechatinfo",
   type : "post",
   async : false,
   data : {
    paytype : $paytype,
    money : $money,
    tjno : $tjno,
    tjreporttype : $tjreporttype
   },
   success : function(d) {
    if (d.resultcode == "1000") {
     //當(dāng)請求成功時(shí),設(shè)置二維碼圖片地址
     $("#codeimg").attr('src', d.obj);
     $("#orderid").val(d.attributes.orderid);
     ////當(dāng)請求成功時(shí),啟動(dòng)定時(shí)任務(wù),每隔3秒去后臺(tái)查詢一次訂單是否成功
     f = setinterval(getorder, 3000);
     // getorder(true);
    }
   }
  });
  $(".selpaycon").css("display", "none");
  $(".weixinpay").css("display", "block");
 });

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

原文鏈接:https://blog.csdn.net/liehuzunzhe/article/details/54615136

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩精品视频一区二区三区 | 综合色网站 | 日韩美女毛片 | 国产毛片视频 | 日韩欧美在线观看一区二区三区 | 免费在线一区二区 | 国产资源在线播放 | 亚洲欧美第一页 | 欧美啪啪 | 免费观看日韩 | 日韩在线观看 | 可以免费看黄的网站 | 成人区精品一区二区毛片不卡 | 国产免费一区二区三区 | 成人国产 | 久久久久久久久成人 | 亚洲综合国产 | 羞羞视频在线免费观看 | 91精品国产综合久久久久久 | 中文字幕乱码亚洲无线三区 | 国产精品无码永久免费888 | 国产一区中文字幕 | 欧美精品免费在线 | 久久国产综合 | 精品中出 | 午夜精品在线 | 97超碰免费 | 中文字幕日韩在线 | 亚洲国产区 | 国产精品美女久久久久久久网站 | 一区视频 | 国产一级毛片aaa | 欧美日韩中文 | 午夜精品久久久久久久久久久久 | 欧美一级网站 | 嘿嘿视频在线观看 | 人人爱人人草 | 国产h片在线观看 | 午夜精品 | 国产精品久久久久免费a∨ 欧美黄色精品 | 久久亚洲综合 |