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

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

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

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java實(shí)現(xiàn)微信支付結(jié)果通知

java實(shí)現(xiàn)微信支付結(jié)果通知

2021-07-01 14:42東邊的小山 Java教程

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

支付完成后,微信會(huì)把相關(guān)支付結(jié)果和用戶信息發(fā)送給商戶,商戶需要接收處理,并返回應(yīng)答。

對(duì)后臺(tái)通知交互時(shí),如果微信收到商戶的應(yīng)答不是成功或超時(shí),微信認(rèn)為通知失敗,微信會(huì)通過(guò)一定的策略定期重新發(fā)起通知,盡可能提高通知的成功率,但微信不保證通知最終能成功。 (通知頻率為15/15/30/180/1800/1800/1800/1800/3600,單位:秒)

注意:同樣的通知可能會(huì)多次發(fā)送給商戶系統(tǒng)。商戶系統(tǒng)必須能夠正確處理重復(fù)的通知。
推薦的做法是,當(dāng)收到通知進(jìn)行處理時(shí),首先檢查對(duì)應(yīng)業(yè)務(wù)數(shù)據(jù)的狀態(tài),判斷該通知是否已經(jīng)處理過(guò),如果沒(méi)有處理過(guò)再進(jìn)行處理,如果處理過(guò)直接返回結(jié)果成功。在對(duì)業(yè)務(wù)數(shù)據(jù)進(jìn)行狀態(tài)檢查和處理之前,要采用數(shù)據(jù)鎖進(jìn)行并發(fā)控制,以避免函數(shù)重入造成的數(shù)據(jù)混亂。

特別提醒:商戶系統(tǒng)對(duì)于支付結(jié)果通知的內(nèi)容一定要做簽名驗(yàn)證,防止數(shù)據(jù)泄漏導(dǎo)致出現(xiàn)“假通知”,造成資金損失。

 

java" id="highlighter_262719">
?
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
//支付結(jié)果通知接口
 
  @requestmapping("/qlydweixinotify.do")
  public void weixinotify(httpservletrequest request,
      httpservletresponse response) {
    printwriter out = null;
    stringbuffer xmlstr = new stringbuffer();
    try {
      bufferedreader reader = request.getreader();
      string line = null;
      while ((line = reader.readline()) != null) {
        xmlstr.append(line);
      
      logger.getlogger(getclass()).debug("支付回調(diào)通知:"+xmlstr.tostring());
      //檢查xml是否有效
      boolean flag=signature.checkissignvalidfromresponsestring(xmlstr.tostring());
      weixinnotifyresult result=null;
      if(flag){
        notifyresdata wxdata=(notifyresdata) util.getobjectfromxml(xmlstr.tostring(),notifyresdata.class);
        if(wxdata !=null){
          if("success".equals(wxdata.getreturn_code())&&"success".equals(wxdata.getresult_code())){
            orderpayinfo orderpayinfo = new orderpayinfo();
            orderpayinfo.setordernum(wxdata.getout_trade_no());
            orderpayinfo.setpaynum(wxdata.gettransaction_id());
            orderpayinfo.setpayprice((double)wxdata.gettotal_fee()/100+"");
            orderpayinfo.setpaysource(wxdata.getopenid());
            orderpayinfo.setpaytime(wxdata.gettime_end());
            orderpayinfo.setpaytype("2");//1支付寶,2微信支付
            ordermessage returnmessage = orderproductserver
                .completeproductorder(orderpayinfo);
            if (orderstatus.fail.equals(returnmessage
                .getorderstatus())) {
              logger.getlogger(getclass()).error("遠(yuǎn)程接口完成訂單失敗");
              result=new weixinnotifyresult("fail");
              result.setreturn_msg("遠(yuǎn)程接口完成訂單失敗");
            } else {
              result=new weixinnotifyresult("success");
              result.setreturn_msg("成功");
            }
          }else{
            result=new weixinnotifyresult("fail");
            result.setreturn_msg("失敗");
          }
        }else{
          result=new weixinnotifyresult("fail");
          result.setreturn_msg("解析參數(shù)格式失敗");
        }
      }else{
        result=new weixinnotifyresult("fail");
        result.setreturn_msg("簽名失敗");
      }
      response.getwriter().write(result.tostring());
    } catch (exception e) {
      logger.getlogger(getclass()).error("qlydweixinotify.do", e);
      responedeal.getinstance().sendresponsestr(response, "404", "連接超時(shí)");
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }

模擬http請(qǐng)求工具類:

httpsrequestutil.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
package com.qlwb.weixin.util;
 
import java.io.ioexception;
 
import org.apache.commons.httpclient.httpclient;
import org.apache.commons.httpclient.httpexception;
import org.apache.commons.httpclient.methods.postmethod;
import org.apache.commons.httpclient.methods.requestentity;
import org.apache.commons.httpclient.methods.stringrequestentity;
import org.apache.log4j.logger;
 
import com.qlwb.weixin.common.configure;
import com.qlwb.weixin.common.util;
import com.qlwb.weixin.protocol.pay_protocol.wxpayreqdata;
import com.qlwb.weixin.protocol.payquery_protocol.payqueryreqdata;
 
public class httpsrequestutil {
 
  /**
   *
   * @方法名稱:sendwxpayrequest
   * @內(nèi)容摘要: <發(fā)送統(tǒng)一下單請(qǐng)求>
   * @param body
   * @param outtradeno
   * @param totalfee
   * @param spbillcreateip
   * @return
   * string
   * @exception
   * @author:鹿偉偉
   * @創(chuàng)建日期:2016年2月19日-下午2:24:05
   */
  public string sendwxpayrequest(string body,string detail,string outtradeno,int totalfee,string spbillcreateip
      )
 
  {
    // 構(gòu)造http請(qǐng)求
    httpclient httpclient = new httpclient();
 
    postmethod postmethod = new postmethod(configure.pay_api);
 
    wxpayreqdata wxdata = new wxpayreqdata(body,detail,outtradeno,totalfee,spbillcreateip);
 
    string requeststr="";
    requeststr=util.convertobj2xml(wxdata);
    // 發(fā)送請(qǐng)求
    string strresponse = null;
    try {
      requestentity entity = new stringrequestentity(
          requeststr.tostring(), "text/xml", "utf-8");
      postmethod.setrequestentity(entity);
      httpclient.executemethod(postmethod);
      strresponse = new string(postmethod.getresponsebody(), "utf-8");
      logger.getlogger(getclass()).debug(strresponse);
    } catch (httpexception e) {
      logger.getlogger(getclass()).error("sendwxpayrequest", e);
    } catch (ioexception e) {
      logger.getlogger(getclass()).error("sendwxpayrequest", e);
    } finally {
      postmethod.releaseconnection();
    }
    return strresponse;
  }
  /**
   *
   * @方法名稱:orderqueryrequest
   * @內(nèi)容摘要: <查詢訂單信息>
   * @param transaction_id 微信的訂單號(hào),優(yōu)先使用
   * @return
   * string
   * @exception
   * @author:鹿偉偉
   * @創(chuàng)建日期:2016年2月19日-下午2:44:11
   */
  public string orderqueryrequest(string transactionid, string outtradeno
      )
 
  {
    // 構(gòu)造http請(qǐng)求
    httpclient httpclient = new httpclient();
 
    postmethod postmethod = new postmethod(configure.pay_query_api);
 
    payqueryreqdata wxdata = new payqueryreqdata(transactionid,outtradeno);
 
    string requeststr="";
    requeststr=util.convertobj2xml(wxdata);
    // 發(fā)送請(qǐng)求
    string strresponse = null;
    try {
      requestentity entity = new stringrequestentity(
          requeststr.tostring(), "text/xml", "utf-8");
      postmethod.setrequestentity(entity);
      httpclient.executemethod(postmethod);
      strresponse = new string(postmethod.getresponsebody(), "utf-8");
 
    } catch (httpexception e) {
      logger.getlogger(getclass()).error("orderqueryrequest", e);
    } catch (ioexception e) {
      logger.getlogger(getclass()).error("orderqueryrequest", e);
    } finally {
      postmethod.releaseconnection();
    }
    return strresponse;
  }
}

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

原文鏈接:https://blog.csdn.net/yelin042/article/details/80636540

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 美女全身体光羞羞漫画 | 婷婷综合七月激情啪啪 | 草莓香蕉绿巨人丝瓜榴莲18 | 插入粉嫩 | 精品一区二区三区色花堂 | 美女脱了内裤张开腿亲吻男生 | 男女男在线精品网站免费观看 | 无限时间看片在线观看 | 国产专区亚洲欧美另类在线 | 亚洲成在人线视频 | 好男人在线观看免费高清2019韩剧 | 亚洲精品成人AV在线观看爽翻 | 黑人巨大和日本娇小中出 | 成人在线观看视频免费 | 好湿好紧太硬了我太爽了网站 | 免费操比视频 | 亚洲XXX午休国产熟女屁 | 天堂男人在线 | 日韩欧美国产综合精品 | 韩国日本在线观看 | 99久久一香蕉国产线看观看 | 日韩精品视频美在线精品视频 | www.尤物| 国产女主播福利在线 | 国产精品nv在线观看 | 操老逼视频| 国产99热99 | nxgx在线观看国产中文 | 天堂avav | 国产18在线 | 91热爆在线 | 婷婷丁香色综合狠狠色 | 亚洲人成伊人成综合网久久 | 极品久久 | 啊好大好爽 | 大伊香蕉精品视频一区 | 欧美三级小说 | 国产成人一区二区三区视频免费蜜 | 欧美成人免费一区在线播放 | 肥胖女人一级毛片 | 日本大片免aaa费观看视频 |