h5 applet access WeChat payment development

First of all, when making payment, you need to confirm whether the official account (mini program) of your project is a merchant. Go to the official website of the WeChat public platform (https://mp.weixin.qq. com/) Confirm (log in to the public platform, click WeChat Pay in the navigation bar, then click the activate button, fill in the relevant information according to the requirements, upload the relevant materials, and submit for review .The review time is generally 7 working days.)

ps: General company development does not require confirmation

JSAPI calls up payment

Process: Place order->Initiate payment->Return results Jump back to this page

Development preparation:

1:Configure and authorize the project address (the address needs to be complete) (the configuration is the project address where you click to pay to call up WeChat)

2:Get code (prepare to get openid)

window.location.href= = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxff1*****4127347a&redirect_uri=http://ww*****erification&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect'

  1. Address: Fixed and hard-coded      
  1.  Appid: It needs to be the appid of the payment merchant. Obtain it from the WeChat public platform. Settings-->Basic Settings

redirect_uri: The page that jumps back after successfully obtaining user information. It needs to be prepared in advance by the paying merchant. Obtained from the WeChat public platform. Official account settings-->Function settings. Otherwise, error 10003 will be reported.

  1. response_type: fixed and hard-coded
  2. Scope: Obtain basic information of the user

snsapi_base can only obtain access_token and openID

snsapi_userinfo can obtain more detailed user information, such as avatar, nickname, gender, etc.

  1. State: Fixed and hard-coded

After opening this address, the user's code is written on the address. Take the returned code.  

3: Obtain openid: Use the code to request the background. You need background assistance to obtain openid

For example:

"http://192.168.2.******?code=" + loginRes.code,

WeixinJSBridge.invoke(

      'getBrandWCPayRequest', {

    

         "timeStamp":"139571***654", //Timestamp, number of seconds since 1970     

         "nonceStr":"e61463f***1f366cccfbbb444", //random string     

         "package":"prepay_id=u8023*******gsdg888",     

         "signType":"MD5", "WeChat signature method:"     

         "paySign":"70EA570631E4**********4C63FF7FADD89" //WeChat signature

      },

4:Tuition WeChat lower part:

https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi   Initiate a request using openid and the data returned by the background ---> Return: res:"prepay_id": "************ "

5: You have already entered WeChat at this time, and the method built into WeChat directly is ok:

onBridgeReady(){

   WeixinJSBridge.invoke(

      'getBrandWCPayRequest', {

    

         .     

         "nonceStr":"e61463*****cccfbbb444", //random string     

         "package":"prepay_id=u802*****dfgsdg888",     

         "signType":"MD5", "WeChat signature method:"     

         "paySign":"70EA570*****BB79628FBCA90534C63FF7FADD89" //WeChat signature

      },

      function(res){

      if(res.err_msg == "get_brand_wcpay_request:ok" ){

      // Use the above method to determine the front-end return. The WeChat team solemnly reminds:

            //res.err_msg will return ok after the user’s payment is successful, but it does not guarantee that it is absolutely reliable.

      }

   });

}

Monotonous payment under H5:

1:Configure the business domain name, JS interface security domain name, and web page authorization domain name in Settings and Development>Official Account Settings>Function Settings. The payment function page must be under the link of this domain name.

2: You need to log in to the merchant platform corresponding to the merchant account--"Product Center"--"Development Configuration" and add the domain name for requesting WeChat orders (the domain name must be registered through ICP, no need to fill in http(s)://)

2:Lower part

 When calling the background interface, you will receive an address (for example: weixin   You can add: '&redirect_url='  + encodeURIComponent(window.location.href)

3:Payment

   Jump to this address and pay,

4: The user completes the payment or cancels the payment at the WeChat payment checkout and returns to the merchant page (the default is to return to the payment initiation page) (WeChat processing)

5: If you don’t want to default: Just add redirect_url at the end to jump to your own page.

Mini program payment:

1: This mini program must have permission to enable WeChat payment WeChat public platform function-->WeChat payment

2: Call the WeChat login interface to obtain the code (because you only need a code, there is no need to pass the code to synchronize the login status)

uni.login({ }//code

                    provider: 'weixin',

                    success: function(wxcode) {

                        console.log(wxcode.code)

                    }

})

3: After getting the code, request the back-end interface to get the data required to initiate payment.

uni.request({

url: "http://192.*****9555/pay/cr*****Ord*****3?code=" + loginRes.code,

data: {},

method: "POST",

})

4: After getting the corresponding data, call up the WeChat payment interface (if you call uni package, you need to write that the service provider is WeChat, if you call WeChat package, you don't need to)

uni.requestPayment({

provider: 'wxpay',

timeStamp: res[1].data.timeStamp,

nonceStr: res[1].data.nonceStr,

signType: res[1].data.signType,

paySign: res[1].data.paySign,

package: res[1].data.packageValue,

success: function(res) {

uni.showToast({

title: 'Payment Successful'

});

console.log(res)

},

Attachment: WeChat refund

Guess you like

Origin blog.csdn.net/weixin_48091030/article/details/126342356