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

What are the steps for IOS Wechat to develop payment?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the steps of IOS Wechat development payment, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

Text:

1. Before you start using WeChat Pay, there are some things that developers must know. Open the following link:

Pay.weixin.qq.com/wiki/doc/api/app.php?chapter=3_1

Then you can see the following page. This is the development document of WeChat Pay merchant platform. A lot of things can be consulted and understood. When you encounter problems when developing and using Wechat SDK payment function, you can also look for relevant information here:

Then, tell the reader that click "payment account > payment account" in this development document, and then scroll to the bottom of the current page to see about APPID:

Note: this APPID is necessary to use WeChat Pay in development, and this APPID can only be obtained by merchants through necessary procedures such as registering on the WeChat Pay platform, spending 300RMB, filling in a lot of relevant important information, and uploading a business license.

In commercial app applications, when customers consume using app Wechat, the program finds the merchant based on this unique APPID, and then transfers the amount of the consumer to the merchant's account.

Benefits for developers: for developers, the WeChat Pay platform provides Demo for testing, as well as useful APPID for testing code in the Demo source code. In this way, the developer eliminates the need to spend 300 yuan on an APPID.

2. In order for readers to learn the process of using Wechat SDK more conveniently and pertinently, I set up an ordinary project to use Wechat SDK directly and easily, and complete WeChat Pay.

Pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1

Click in and download SDK. In addition, download Demo. You can refer to the use of the learning source code, or you can save it for further exploration:

In the new project, we drag the downloaded SDK into it. There are five files in the downloaded SDK file. You don't have to keep that read_me.txt in the project, as you like, but you can open and read the prompts inside:

We first open the read_me.txt file, in fact, it is about the recent version of the update to solve the problem, and the use of the SDK attention, the red box part I will be used in the later operation, SO this read_me file is very important oh.

3. OK, let's follow the read_me.txt to do the necessary process:

After the Xcode 7 version, you need to import the framework and link libraries:

If it is before XCode 7, you will probably need to manually import frameworks such as Foundation.framework, UIKit.framework, and so on.

Then, as prompted by read_me.txt, we copy that plist code into the info.plist file:

1 LSApplicationQueriesSchemes2 3 weixin4 5 NSAppTransportSecurity6 7 NSAllowsArbitraryLoads8 9

Then switch the info.plist file to the Property list display view, and you will see two more items:

App Transport Security Settings needs to be manually added in development later on by XCode7, because iOS9 restricts access to the http protocol by default.

LSApplicationQueriesSchemes can whitelist the URL Schemes to be used, so that the current application can use Wechat's relevant capabilities (sharing, favorites, payment, login, etc.).

Finally, there is one more operation, oh, set the APPID to be used by WeChat Pay to URL Schemes [British ski roomm].

4. OK, we can start typing the code:

We can open the Demo program downloaded by WeChat Pay and find the APPID for testing in the source code of its AppDelegate:

Then I went back to the project I built and wrote down WeChat Pay's process:

Since we want to register Wechat, let's take a look at the header file of Wechat SDK and find that only two registration methods are provided and the comments are very clear:

Then after we import the header file, we register directly according to the existing APPID:

Good, actually step: 1, import WeChat Pay SDK, register WeChat Pay. Then 2. Set Wechat APPID to URL Schemes.

Then we need to initiate payment and transfer it to WeChat Pay. Before that, let's directly take a look at the Demo provided to us by Wechat:

Finally, we found the complete source code of WeChat Pay that can be used directly in Demo:

If you copy this paragraph directly into my project, developers with a little experience will notice some. For example, the Demo source code uses MRC's autorelease, which you can remove manually, and the class method can be replaced with an instance method, based on your actual project development requirements:

1-(NSString *) jumpToBizPay {2 3 / / = = 4 / / V3&V4 payment process is realized 5 / / Note: for parameter configuration, please check the server side Demo 6 / / Update time: November 20, 2015 7 / / = = 8 NSString * urlString = @ "http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios"; 9 / the resolution server returns json data 10 NSError * error 11 / / load a NSURL object 12 NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString:urlString]]; 13 / / put the requested url data into the NSData object 14 NSData * response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 15 if (response! = nil) {16 NSMutableDictionary * dict = NULL 17 / / IOS5 has its own parsing class NSJSONSerialization to parse the data from response into the dictionary 18 dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; 19 20 NSLog (@ "url:%@", urlString); 21 if (dict! = nil) {22 NSMutableString * retcode = [dict objectForKey:@ "retcode"] 23 if (retcode.intValue = = 0) {24 NSMutableString * stamp = [dict objectForKey:@ "timestamp"]; 25 26 pounds / adjust WeChat Pay 27 PayReq* req = [[PayReq alloc] init]; 28 req.partnerId = [dict objectForKey:@ "partnerid"] 29 req.prepayId = [dict objectForKey:@ "prepayid"]; 30 req.nonceStr = [dict objectForKey:@ "noncestr"]; 31 req.timeStamp = stamp.intValue;32 req.package = [dict objectForKey:@ "package"] 33 req.sign = [dict objectForKey:@ "sign"]; 34 [WXApi sendReq:req] 35 / / Log output 36 NSLog (@ "appid=%@\ npartid=%@\ nprepayid=%@\ nnoncestr=%@\ ntimestamp=%ld\ npackage=%@\ nsign=%@", [dict objectForKey:@ "appid"], req.partnerId,req.prepayId,req.nonceStr, (long) req.timeStamp,req.package,req.sign); 37 return @ " 38} else {39 return [dict objectForKey:@ "retmsg"]; 40} 41} else {42 return @ "the server returned an error and did not get the json object"; 43} 44} else {45 return @ "Server returned error"; 46} 47}

Oh, by the way, there is another simple but necessary operation that I forgot to show:

Further, we can find two very useful methods in Wechat's SDK source port file. You can also open the developer documentation on WeChat Pay platform to find an introduction to these two methods:

And then I applied it to my project.

OK, that's it, step: 3. Initiate WeChat Pay, adjust Wechat and finish it here.

The last thing you need to do is to process the return information returned by WeChat Pay and use the Wechat function, no matter whether the payment is successful or failed, or even the user cancels the payment himself, you will need to return to the current application and return relevant information.

Here, you need to use Wechat SDK's proxy protocol and method to deal with the returned information:

In the header file of Wechat SDK, we can find the protocol protocol:

Well, let's also take a look at how it works in the official Demo:

We only need to use some of the code framed in red below and copy it directly to use it:

Go back to my simple project and paste it directly into it:

So there are two main things in the return information: the resp.errCode error code and the reason for the resp.errStr error, which are often encountered in actual development, so it is also a detail that will be asked in the interview.

Then you can click on the link: pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_5 can be found in the official development documentation:

Then, according to the actual development needs, we may also need to send back the relevant information about Wechat app:

Add a proxy method to the current AppDelegate.m file:

5. Here, you have completed the whole process of using WeChat Pay. Now you can test it with your real machine, because the simulator is not easy to install Wechat.

Reprint indicates the source: www.cnblogs.com/goodboy-heyang/p/5255818.html, respect the fruits of labor.

Finally, add that there is also Wechat explanation and source code on the github, which you can also learn:

Github.com/renzifeng/WXPay

However, for those who bought a developer account for $99, it is estimated that the source code downloaded on the github cannot be tested directly with the real machine, because the above project instance was created earlier. At that time, XCode did not support real machine testing when there was no developer account.

Thank you for reading this article carefully. I hope the article "what are the steps for the development and payment of IOS Wechat" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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