Micro-credit Payment development IOS Graphics tutorial case _ios

Source: Internet
Author: User
Tags error code instance method

Foreword: The following introduces the details of the development process of micro-letter payment, illustrated, you can follow my essay process through the code. The package one also learned the micro-credit to pay. And payment is also the content of the interview frequently asked.

    

Body:

1, first of all, before starting to use micro-letter payment, there are some things developers must know, open the following link:

Https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=3_1

Then you can see the following page, this is the micro-letter payment merchant Platform development document, a lot of things can be consulted and understand, in the development of the use of micro-letter SDK Payment function, encountered problems can also go to this to find relevant information:

Then, also tell the reader to click on the "Pay 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 the development of the use of micro-letter payment must be used, and this appid only merchants through the micro-letter payment platform registration, spend a 300 yuan, fill in a lot of relevant important information, but also upload the business license and other necessary procedures to obtain the AppID.

Commercial app apps, where customers use app micro-letters, will find businesses based on this unique AppID, and then pass the amount of consumer money to a merchant's account.

Benefits to developers: for developers, micro-credit payment platform to provide a test demo, but also in the demo source code to provide useful for testing the AppID. So the developer removes the need to spend 300 yuan to buy a appid.

2, in order to readers more convenient and more targeted to learn the use of this micro-letter SDK, I set up a common project, directly above the simple use of micro-letter SDK, and the completion of micro-letter payment.

Https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1

Click to download the SDK, and also to download the demo, you can take reference to the use of the source of learning, you can also save further exploration:

In the new project, we dragged the downloaded SDK in, downloaded the SDK file, there are five files, that read_me.txt can not keep the project, as you like, but you can open the reading of the hint information:

  

We first open the Read_me.txt file, in fact, it is in the last few versions of the update to solve the problem, as well as the use of the SDK notes, the red box up the part I will use in the later operation, so this Read_me file is very important oh.

3, OK, we will follow the read_me.txt to do the necessary process:

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

    

If it is Xcode 7, it is estimated that you will need to manually import the Foundation.framework, Uikit.framework, and other frameworks.

Then, as prompted by Read_me.txt, we copy the plist code into the Info.plist file:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key> nsallowsarbitraryloads</key>
<true/>
</dict>

Then switch the Info.plist file to the property list display view, and you'll see two more items:

The APP transport security settings are XCode7 to be manually added in development later, because iOS9 restricts access to the HTTP protocol by default.

Lsapplicationqueriesschemes is the URL schemes that can be used as a whitelist, so current applications can use micro-letter related capabilities (sharing, collection, payment, login, etc.).

Finally there is an operation Oh, the micro-letter payment to be used to set the AppID URL schemes [English skiːm].

4, OK, we can start knocking the code:

We can open the micro-credit payment platform to download the demo program, in its appdelegate source code to find the test AppID:

Then go back to the project you built, and write down the micro-letter payment process:

Now that we're going to register for the micro-mail, let's look at the first file in the micro-trust SDK and find that only two registration methods are available, and the notes are clear:

After we import this header file, we register directly according to the existing AppID:

Well, in fact, steps: 1, the letter to pay the SDK, registered micro-letter payment. Then 2, set the micro-letter AppID as the URL schemes the front has been done.

Then we need to proceed to 3, initiate payment, and tune its micro-letter payment, before we go directly to the demo that the micro-letter official provided us:

Finally we found the demo in the complete can be directly used in this part of the launch of micro-letter payment Source:

The direct copy to my project, there are a little experience developers will notice some, such as the demo source using the MRC autorelease, you can manually remove, class method can be replaced by instance method, according to your actual project development requirements:

-(NSString *) Jumptobizpay {//============================================================//V3&AMP;V4 payment Process Implementation//NOTE: Ginseng Number configuration Please view the server side demo//update time: November 20, 2015//============================================================ NSString *
 URLString = @ "Http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios";
 Parsing server-side returns JSON data Nserror *error;
 Loads a Nsurl object nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:urlstring]]; Place the requested URL data in the NSData object NSData *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error
 : nil];
 if (response!= nil) {nsmutabledictionary *dict = NULL; IOS5 the parsing class nsjsonserialization the data from the response to the dictionary dict = [nsjsonserialization jsonobjectwithdata:response options:
 
 Nsjsonreadingmutableleaves error:&error];
 NSLog (@ "url:%@", urlstring);
 if (dict!= nil) {nsmutablestring *retcode = [dict objectforkey:@ "Retcode"];
 
 if (Retcode.intvalue = = 0) {nsmutablestring *stamp = [dict objectforkey:@ "timestamp"]; Tune Up MicroLetter Payment payreq* req = [[Payreq alloc] init];
 Req.partnerid = [Dict objectforkey:@ "Partnerid"];
 Req.prepayid = [Dict objectforkey:@ "Prepayid"];
 REQ.NONCESTR = [Dict objectforkey:@ "Noncestr"];
 Req.timestamp = Stamp.intvalue;
 Req.package = [dict objectforkey:@ "package"];
 Req.sign = [dict objectforkey:@ "sign"];
 [Wxapi Sendreq:req]; Log output 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);
 return @ "";
 }else{return [dict objectforkey:@ "retmsg"];
 }else{return @ "server returned error, no JSON object acquired";
 }else{return @ "server returned error";
 }
}

Oh, yes, there's a very simple but necessary operation. Forget to show it:

Further, we can find two very useful methods in the micro-letter SDK Source Dock file, you can also open the developer's documentation on the micro-credit payment platform to find the introduction of these two methods:

And then I applied it to my project.

OK, so, step: 3, the initiation of micro-letter payment, the transfer of micro-letter to be completed here.

The final thing to do is to process the return of the micro-letter payment return information, using the micro-signaling function, whether payment success and failure, or even the user to cancel the payment, will need to return the current application, and return the relevant information.

Here you need to use the micro-letter SDK processing the return information of the proxy protocol and proxy method:

In the head file of the micro-trust SDK, we can find the protocol protocol:

Well, we'll also take a look at the official demo to see how it is used:

And we just need to use some of the red box code, direct copy to use:

Back to my simple project, paste it directly in:

There are two main things in this return message: Resp.errcode error code and RESP.ERRSTR error reason, these two things are often encountered in the actual development, so it is also the interview will ask a detail.

Then you can go through the point-to-point connection: Https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=8_5 can be found in the official development document:

Then, depending on the actual development requirements, we may also need to return information about the app:

Add a proxy method to the current APPDELEGATE.M file:

5, here, completed the entire use of micro-letter payment process, the following can be used to test your real machine, because the simulator is not easy to install micro-letter.

Finally, the discovery of the Great God GitHub also has micro-letter explanation and source code, we can learn to learn:

Https://github.com/renzifeng/WXPay

However, for no 99 U.S. knives to buy a developer account, the GitHub download source estimates can not directly use the real machine test, because the above project instance was created earlier, when Xcode in the absence of a developer account, does not support the real machine test.

There is also a tweet written by Daniel to pay the letter, and it was written on January 20, 2016:

Http://www.cnblogs.com/jys509/p/5130990.html

The above is the entire content of this article, I hope to help you learn.

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: info-contact@alibabacloud.com 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.