Android WeChat payment-precautions: android payment

Source: Internet
Author: User

Android payment-precautions: android payment

Not all BAT APIs are so easy to use. There are a lot of pitfalls in payment. Let's summarize the pitfalls in payment implementation.

Point 1:

Generation of the PayReq parameter sign

The PayReq object has a parameter packageValue.

PackageValue is used when sign is generated, but the corresponding Key is package. The key here is easy to make a mistake.

List<NameValuePair> signParams = new LinkedList<NameValuePair>();signParams.add(new BasicNameValuePair("appid", req.appId));signParams.add(new BasicNameValuePair("noncestr", req.nonceStr));signParams.add(new BasicNameValuePair("package", req.packageValue));signParams.add(new BasicNameValuePair("partnerid", req.partnerId));signParams.add(new BasicNameValuePair("prepayid", req.prepayId));signParams.add(new BasicNameValuePair("timestamp", req.timeStamp));

Point 2:

Payment callback Method

Use reflection to find the corresponding class and implement the callback

The official descriptions are as follows:

Refer to the SDK Sample in. net. sourceforge. simcpux. implement the WXPayEntryActivity class in the wxapi package path (inconsistent package names or class names will cause callback failure). Implement the onResp function in the WXPayEntryActivity class. After the payment is complete, the APP returns to the merchant APP and calls back the onResp function. The developer needs to receive the notification in the function to determine whether the error code is returned. If the payment is successful, go to the background to query the payment result and then display the user's actual payment result.


1. You need to create a packageName +. wxapi package, for example, your project registration: com. android. qq. Then you need to create a wxapi package under the package name.

2. Create an Activity class named WXPayEntryActivity under the package and implement the interface IWXAPIEventHandler. The payment callback is carried out in the onResp (BaseResp resp) method of the interface.

package;public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


@ Overridepublic void onResp (BaseResp resp) {// process the payment callback}


Signature Test

This is not a pitfall. Many third parties have to test it in this way.

The paid test must correspond to the signed package; otherwise, the payment function cannot be tested.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.