Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize WeChat Pay in Android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to realize WeChat Pay in Android". In daily operation, I believe many people have doubts about how to realize WeChat Pay in Android. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to realize WeChat Pay in Android"! Next, please follow the editor to study!

Pothole one:

Generation of parameter sign of PayReq

The PayReq object has a parameter of packageValue

PackageValue is used when sign is generated, but the corresponding Key is package, and the key here is easy to make mistakes.

List signParams = new LinkedList (); 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))

Pit two:

Payment callback method

Wechat uses reflection to find the corresponding class and implement the callback

The official explanation given by Wechat is as follows:

Refer to Wechat SDK Sample, implement the WXPayEntryActivity class in the net.sourceforge.simcpux.wxapi package path (if the package name or class name is inconsistent, it is impossible to call back), and implement the onResp function in the WXPayEntryActivity class. After the payment is completed, Wechat APP will return to the merchant APP and call back the onResp function, in which the developer needs to receive the notification and determine the error code returned. If the payment is successful, go to the backend to query the payment result and show the user's actual payment result.

The meaning is as follows:

1. You need to create a packageName+.wxapi package, such as: 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 callback of payment is carried out in the onResp (BaseResp resp) method of this interface.

Package com.android.qq.wxapi

Public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

@ Override public void onResp (BaseResp resp) {/ / processing payment callback} so far, the study on "how to implement WeChat Pay in Android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report