IOS- WeChat payment summary

The purpose of this article is to sort out knowledge, consolidate ideas, and study and summarize. You can leave a message if you have any good suggestions. Promote each other! General view, WeChat pay, but also no idea, take a good look at documents. The document is slightly confused. Feel, WeChat, demo, internal functions are integrated into a piece, it is difficult to find. Finally, in all kinds of pits, carefully read the document, silently finished. Will use the web site as follows:
WeChat open platform
WeChat iOS WeChat
business platform online payment document
SDK integrated document general direction: 1. registered WeChat open platform to create application access to appid, APPSecret, apply the payment function, after the success of the application will return some parameters. 2. download WeChat SDK. 3. client request payment orders, the background the interaction with WeChat, returned to the client to pay 4. call parameters. WeChat client, client and server by the WeChat WeChat deal. 5. client and server will receive payment.

1. preparation

(our company’s WeChat company for payment application is finished, created after application to me, but also clear about the process) A. registered developers account into the WeChat open platform, registered developers account (must apply). Apply for developer qualification certification, 300 yuan a year. In addition to using some of the advanced features of WeChat’s open platform, you don’t need to be certified.
IOS- WeChat payment summary
developer qualification certification, B. registered applications to get WeChat developer account, login WeChat open platform, into the management center, create new mobile applications.
IOS- WeChat payment summary
registration application
creation of the application, I will be to everyone, the specific details of the screenshot is not. C. gets app, ID, and appSecret creation success, getting appid and appSecret. Click here to see the following diagram. After the
IOS- WeChat payment summary
gets the app ID and the appSecret
authentication, we return the app, ID, and appSecret we want to get, as shown in the figure below.
IOS- WeChat payment summary
D. to apply for payment verification after login permissions WeChat open platform management center – – create mobile applications to register the corresponding application interface name: WeChat pay – apply for permission to pay. Fill in the data, waiting for review. After success, you receive an email, merchant number, merchant login number and login password. E. account authentication login WeChat open platform – Management Center, to find the corresponding application, view – WeChat payment (interface status – has been obtained) – see the details, follow its prompt steps. Receive the confirmation money and verify it. Verification is through and preparation is complete.
IOS- WeChat payment summary
apply for the opening of payment authority,
opening WeChat payment, and some may not necessarily, some week, and some very long. I don’t know. It’s about time. We’ve been applying for a long time. Click on the
–> see details (see payment details)
IOS- WeChat payment summary

IOS- WeChat payment summary
signed payment application process f. API key F.1 for merchant login account and password
F.2 on WeChat merchant platform — account center – account settings – API security – API key
F.3 installation operation certificate, and then set the key.
IOS- WeChat payment summary
gets the API key
(this step must not forget, in fact, in accordance with the instructions on the mail, go OK. WeChat process is a step wrong, it is easy to go wrong, remember to step by step, don’t waste unnecessary time, WeChat payment application, basic work is ready Summary:
1. and appSecre ID app to create the application to obtain
3. for the opening of the payment function in the mail merchant number and account password
4. business platform, download the certificate, API key added: after creating a mobile application and success will be subject to send mail to Tencent IOS- WeChat payment summary

by email the message we can get important parameters:
(1): AppID
(2): WeChat merchants pay No.
(3): to business platform to complete the assigned to the
(4): API key (to set up their own, must pay attention to the combination of 32 letters and numbers) remember keep secret key, to be used later. $_$; with these parameters, we can develop their own projects.

2. SDK integration and environment configuration

Now let’s build the project together and integrate the WeChat payment SDK. Download the address is as follows:
and Demo official SDK download
IOS- WeChat payment summary

as above, SDK version of 1.7.9, ios9_v3_pay 1. will project we download the SDK into our.
IOS- WeChat payment summary
2. in Target – > General – > Link Binary With Libraries, click the + -> library search system, you need SystemConfiguration.framework libz.tbd libsqlite3.0.tbd CoreTelephony.framework QuartzCore.framework as follows: IOS- WeChat payment summary
3 URL Scheme add library dependencies: to jump between app and
registered WeChat APP platform, will give a a unique identification identifier (APPID).
URL schemes is here to fill out an application in the WeChat development platform appID
open the project -> info-> URL types IOS- WeChat payment summary
URL Scheme 4. configuration (white list looks like a white list configuration can jump, but still write all the better).
IOS- WeChat payment summary

or info.plist -&gt source code to open the right; add the following code < key> LSApplicationQueriesSchemes< /key>
< array> < string> wechat< /string>
< string&gt Weixin; < /string>
< /array> 4. when there will be some strange questions such as the
Terminating app due to uncaught: exception’NSInvalidArgumentException’, reason: __NSArrayM enqueue:] unrecognized selector’-[: sent to -ObjC instance 0x60000024ef40′ buddle Seeting add in the inside of the Other Linker Flags on it. Com + R, if there is no problem, basically the integration is completed, the environment is also configured?.

3. code layout for WeChat payment

Before lifting WeChat, it’s important to know what WeChat’s payment is like. [see official] IOS- WeChat payment summary

business process system and WeChat payment system is interactive:
step 1: the user choose goods, merchants in APP submit orders, choose WeChat to pay.
step 2: merchant background receive user payment form, call WeChat payment unified single interface. See [unified order API].
step 3: unify the single interface, return to the normal prepay_id, and then re sign the signature specification, then transfer the data to the APP. The fields involved in signing are called appid, partnerid, prepayid, noncestr, timestamp, and package. Note: the value of the package format is Sign=WXPay
, step 4: merchant APP tune up WeChat payment. API see this chapter [app end development step description]
step 5: merchant background receive payment notifications. API see [payment results notice API]
step 6: merchant background query payment results. API see [query order API] [online good process sharing] 1, users use APP client, select commodity orders. 2, merchant client (that is, you do APP), the user’s product data to the merchant server, request to generate payment orders. 3, merchant background call unified single order, API to WeChat server sent request, WeChat server generate prepaid single, and generate a prepay_id back to merchant background. 4, the merchant will return this prepay_id back to the merchant client. 5, the user clicks to confirm payment, this time the merchant client calls SDK, open WeChat client, WeChat payment. 6, WeChat launched WeChat server client to the payment request and return the result of payment (by using the interaction between them is prepay_id this parameter, WeChat server to verify WeChat client passed parameters are consistent with that of ID generated in step third). 7, users enter the payment password, WeChat client submit payment authorization, interact with WeChat server, complete the payment. 8, the WeChat server sends the payment results to the WeChat client, and asynchronously sends the payment results notification to the merchant server. 9, merchant clients through the payment results callback interface query the payment results, and check the results of the payment to the background is correct, return the results of the background. 10, merchant client display payment results, complete orders, delivery. The main task of the client 1. tune up, WeChat client launched payment, 2. show payment results, hang up, ready to call WeChat payment, you need to order, signature and other operations, in order to obtain the necessary parameters of WeChat payment. In order to improve security, orders and signature operations are usually done in the background. Including the required parameters: appid, partid, prepayid (merchant) (pre payment order ID), noncestr (random string signature), timestamp (time stamp signature), sign (signature string) six. [1] if the example code generates all the information in the front, including sign signature and MD5 encryption and signature of the order (this method is relatively complicated, there is no official method to simple) you can see the WeChat iOS application integrated payment reference article. Is the official to v3& V4 payment flow, signature and encryption are in [server], as do we, 2 time signature server is done as follows: 1, in the project Appdelegate.m file add WeChat registered payment information, note: if the third party disparts to enjoy the League of friends, in when registering to the front alliance registered on the WeChat registered executive. As follows: #import “AppDelegate.h” #import “WXApi.h” @interface AppDelegate (@end @implementation AppDelegate) – (BOOL) application: (UIApplication * application) didFinishLaunchingWithOptions: (NSDictionary * launchOptions) {/ / [WXApi registration APP, registerApp:@ “wxb4ba3c02aa476ea1”]; return YES;} – (BOOL) application: (UIApplication * APP) openURL: (NSURL *) URL options: (NSDictionary< id> NSString *, options *) {/ / jump to configure URL address in scheme / NSLog (@ “jump to URL scheme in the configuration of –&gt address, URL;% @”); return [WXApi handleOpenURL:url delegate: (id< WXApiDelegate> self];} / / call) successful payment, return to third party applications – (BOOL) application: (UIApplication * application) openURL: (NSURL *) URL sou RceApplication: (NSString *) sourceApplication annotation: (ID annotation) {/ / NSLog (@ **************** -% @ “([url.scheme,; if isEqualToString:@” wx23a1f7f291ef4b3d “return [WXApi handleOpenURL:url”) {delegate: (id< WXApiDelegate> self]; return YES)}}; 2, to send the order information server, obtaining prepaid order parameters WeChat, lift. WechatPayViewController.m #import “WechatPayViewController.h” #import “HYBNetworking.h” #import “WXApi.h” #import “NSString+MD5.h” @interface (WechatPayViewController) / merchant key information, WeChat appID assigned to the merchant, the merchant number, key @property merchants (nonatomic, strong) NSString, *appId, *mchId, *spKey; @end @implementation WechatPayViewController (void) viewDidLoad {[super viewDidLoad]; Do any additional setup after loading / the view. self.view.backgroundColor = [UIColor greenColor]; UIButton *payButton [UIButton = buttonWithType:UIButtonTypeCustom]; =; payButton.bounds = CGRectMake (0, 0, 200, 200); [payButton setImage:[UIImage imageNamed:@ forState:UIControlStateNormal] “[email protected]”]; [payButton addTarget:self action:@selector (payClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:payButton]; / / to determine whether the user to install WeChat / / if the judgment result has been NO, appid may be invalid, here is an invalid if ([WXApi isWXAppInstalled]) {/ / monitoring a notification [[NSNotificationCenter (getOrderPayResult:) defaultCenter] addObserver:self selector:@selector name:@ ORDER_PAY_NOTIFICATION object:nil];}} – (void payClick) {[self easyPay];} / * * http:// as the test data, the general can get data from here can let the server to complete, the client only needs to access to the configuration and to PayReq, WeChat can be lifted; * / – (void) easyPay {[HYBNetworking “http:// getWithUrl:@ params:nil success:^ (ID response) {NSLog (@ “% @”, response); / / configuration transfer from the WeChat payment required parameter PayReq *req alloc] = [[PayReq init]; req.partnerId [response objectForKey:@ = “partnerid”]; req.prepayId [response objectForKey:@ = “prepayid”]; req.package [response objectForKey:@ = “package”]; req.nonceStr [response objectForKey:@ = “noncestr”]; req.timeStamp [[response objectForKey:@ = “timestamp”]intValue]; req.sign [response objectForKey:@ = “sign”]; / / transferred to pay WeChat if ([WXApi sendReq:req]) {NSLog (@ “lift” success);}} fail:^ (NSError *error) {NSLog (@ “% @”, error);}]; #pragma} mark – received the news of the successful payment processing after the corresponding – (void) getOrderPayResu Lt: (NSNotification *) notification {if ([notification.object, isEqualToString:@, success)] {NSLog (@ payment success)} else {NSLog (@ payment failed)}}

Watch out:

1, you create the application boundId must be the same as in your project. 2, don’t forget to configure the URL Scheme application to jump 3, if the payment is completed, stay in WeChat, then check the URLType set in Scheme 4, WeChat can open the client, but open only after the middle of a white “button”, click back to the client, if so, it should be is the prepayid parameter, expired, or not real ID. The code is fine. Special attention is paid to WeChat, two time signature, two ~ ~ ~ ~ 5, online said if APP, which uses the alliance or ShareSDK share, then they do not need to import SDK, otherwise there will be some strange problems, such as mobile phone, WeChat cannot transfer from the client to transfer from the WeChat web page, adjustable but a fleeting… That’s basically because the shared SDK already includes WeChat’s SDK. So if there’s a weird mistake, see if it’s two conflicts! I’m not in conflict because, WeChat, I’m manually integrated, shareSDK is pod integrated. 6, WeChat pay units are points, people who have been pit know! 7, the two time signature process: first signature: client initiated payment request to the server, the server for a signature according to the parameter needed, interact with WeChat’s server, successfully returned data for the second signature. Returns information (advance orders, parameters, etc.) to the client. The client will hoist the WeChat according to the parameters obtained.
article: WeChat
started app pay V3 iOS version
iOS WeChat WeChat
iOS integrated development payment application payment integration
extended article
– WeChat paid simple example code from zero (you can look at the code behind
iOS) micro channel payment method development fool tutorial
iOS- WeChat Demo
if the payment process. This article, useful for you, or help you, please, I eat popsicles, cool off. Not playing games, learning together, what if there is a better suggestion, please forward, or what is a good method. Thanks!!!