激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

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

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

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

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

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

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

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

特別提醒:商戶系統(tǒng)對于支付結(jié)果通知的內(nèi)容一定要做簽名驗證,防止數(shù)據(jù)泄漏導致出現(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("遠程接口完成訂單失敗");
              result=new weixinnotifyresult("fail");
              result.setreturn_msg("遠程接口完成訂單失敗");
            } 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", "連接超時");
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }

模擬http請求工具類:

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)一下單請求>
   * @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請求
    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ā)送請求
    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 微信的訂單號,優(yōu)先使用
   * @return
   * string
   * @exception
   * @author:鹿偉偉
   * @創(chuàng)建日期:2016年2月19日-下午2:44:11
   */
  public string orderqueryrequest(string transactionid, string outtradeno
      )
 
  {
    // 構(gòu)造http請求
    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ā)送請求
    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;
  }
}

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩精品一区二区在线播放 | 欧美日韩一 | 日本a级一区 | 国产一级做a | 久久国产一二区 | 久久成人激情视频 | 欧美亚洲国产一区二区三区 | 国产精品一区二区免费在线观看 | 亚洲影视中文字幕 | 性欧美视频在线观看 | 91精品国产91久久久 | 国产免费高清在线 | 男女羞羞视频在线观看免费 | 黄色大片在线观看 | 91一级毛片 | 被玩坏了的女老师(高h np) | 毛片久久 | 看毛片的网址 | 久久99精品久久久久久秒播放器 | 国产在线精品一区二区三区不卡 | 日韩精品一二三 | 在线男人天堂 | 色综合视频网 | 午夜久久久精品一区二区三区 | 一级性生活免费视频 | 国产精品白嫩白嫩大学美女 | 国产一级大片 | www.成人免费| 日本在线精品视频 | 精品国产一区二区三区四区阿崩 | 日日做夜夜爱 | 中文字幕在线视频日本 | 欧美成a人片在线观看久 | 久久国产成人精品国产成人亚洲 | 国产成年人网站 | 国产91精品久久久久久久 | 美女黄色影院 | 欧美日韩亚洲成人 | 欧美三级欧美成人高清www | 青草视频在线观看视频 | 久久性生活免费视频 |