JAVA WeChat scan code payment mode 2 function realization and callback

Reference blog http://blog.csdn.net/bestlove12345/article/details/51858203

Mode 2 does not need to set the callback on the WeChat official website, it needs to be set in the code.

Formal payment requires external network support. We can use it to simulate and test external network access by downloading the natapp software.

Download a natapp software windows version

 Run the software exe, see screenshot.

The software must be: eclipse+ jdk1.8 + tomcat8.5, because the new features of servlet3.0 are used

After the eclipse demo runs, the browser link

 http://localhost/weixin_pay/

 

Change to external network: http://ff3v7a.natappfree.cc/weixin_pay

 

http://ff3v7a.natappfree.cc/weixin_pay/pay?out_trade_no=dhdheheheh12135&body=hnnkj&total_fee=1

-----------------------------------------------

order cannot be 1,

 To set the order number eg: dhdheheheh12133

Price 1: represents 1 point

 

-------------------------------

Generate QR code before payment

--------------------------------------

resXml----<xml><return_code><![CDATA[SUCCESS]]></return_code>

<return_msg><![CDATA[OK]]></return_msg>

<appid><![CDATA[wx1mmmm9mmmm37fji8bd9]]></appid>

<mch_id><![CDATA[149mm1nn08932]]></mch_id>

<nonce_str><![CDATA[QzoyHZ7lv0gqByTe]]></nonce_str>

<sign><![CDATA[jimmkllmmlmllml]]></sign>

<result_code><![CDATA[SUCCESS]]></result_code>

<prepay_id><![CDATA[mlmlmllmlml]]></prepay_id>

<trade_type><![CDATA[NATIVE]]></trade_type>

<code_url><![CDATA[weixin://wxpay/bizpayurl?pr=YF9KiHf]]></code_url>

</xml>

 

----------------------------------------------------------------

after payment

 

----------------------------------------------------

weixin :// wxpay / bizpayurl ? pr =YF9KiHf-------

{appid=mllmlmlmlllm, bank_type=CFT, cash_fee=1, fee_type=CNY, is_subscribe=N, mch_id=132322434343, nonce_str=31313131, openid=jijijjijijiiiijiji, out_trade_no=dhdheheheh12135, result_code=SUCCESS, return_code=SUCCESS, sign=jiiuiui, time_end=20171116213218, total_fee=1, trade_type=NATIVE, transaction_id=4200000016201711165108252851}

mch_id:232322232323232

openid:jjjjjjjjjjjjjjjjjj

is_subscribe:N

out_trade_no:jjjjjjjjjjjjj

total_fee:1

 

 

------------------------------

 

publicclassPayConfigUtil{

publicfinalstatic String APP_ID = "wxbd9" ; //These are provided by WeChat when applying for a public account

publicfinalstatic String APP_SECRET = "80305" ; //These are provided by WeChat when applying for a public account

publicfinalstatic String MCH_ID = "149302" ; //These are provided by WeChat when applying for a public account

publicfinalstatic String API_KEY = "0Y5FPUJIDPK" ; //These are provided by WeChat when applying for a public account

public final static String NOTIFY_URL = "http://ff3v7a.natappfree.cc/weixin_pay/WXReturnController" ; //Callback address after successful payment, the project must be deployed in an environment accessible to the external network

public final static String TRADE_TYPE = "NATIVE" ; //Select NAVITE, then the uploaded ip can be the local ip paid by the machine

public final static String API_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder" ; //Scan code payment interface, see WeChat official API for details

 

Just change the configuration to the one you applied for, run this demo, and use this example for callback first. The later callback is changed to the url intercepted by the springmvc controller of your own domain name, and you can test it yourself.

For a detailed example, see the demo. You can run the demo by changing it to your own. I ran it successfully, then the configuration was randomly changed to prevent leaking the key, and I uploaded it.embarrassment

 

}

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326583621&siteId=291194637