Original title: IOS integrated WeChat or Alipay pay the payment function of the
2016.7.1. The SDK used in this article may be a bit old because of Apple’s mandatory requirement for IPv6, and the audit may be rejected if used, demo. Proposed to upgrade the new version of the SDK, and then integrated, the method is similar, what problems, welcome to exchange
When integrated with ShareSDK social sharing is integrated with WeChat or Alipay
payment payment function
(WeChat and Alipay respectively integrated payment, Ping++ payment integration around… Please)
2016.01.07 update (onResp Xcode7.2 callback method after modifying the WeChat IOS9.2 client operating procedures are not returned to the WeChat executive Bug)
Http://yun.baidu.com/share/link? Shareid=187711184& uk=3055516665
No nonsense, first throw link
First, you need to have the WeChat platform developers account (https://open.weixin.qq.com/, or by Baidu WeChat open, Alipay paid similarly, the same below), and you have to register the application integration in your developer account, and obtain payment authority (usually this step is not to consider the need for programmers, are their clients get, you only need to know, did not pay for the privilege of application, can not be integrated payment).
Second, after registering your application, through the review, you will be given an open platform to give you the AppID and AppSecret that belong to this application
Third, download the IOS SDK from the resource center of the development platform (or what is called the document center, the SDK Center) (documents can also be downloaded for easy access). My Demo this time is the ShareSDK share and third party login that was integrated before, so the WeChat SDK in ShareSDK is used directly.
(PS, here before users have had with ShareSDK in WeChat SDK does not support the payment function, here you can pay, Mob should be integrated as well, if you download can not use it, can go to the WeChat official download the official SDK, 10M or so, the ShareSDK of WeChat SDK replace replacement, the time to pay attention, can not only replace the file, to be optimistic about the project in the Target tab file path to delete the old file path, otherwise it may be the old file path will cover the new file path, to replace no effect or collapse).
Fourth, copy the downloaded SDK into the project folder, and then “AddFilesTo” your project”,
(notice here that Add is checked for CopyItemsIfNeeed, or there might be annoying bugs where no path can be found)
Fifth, configure your project.
1 add the system dependent libraries, (here I use ShareSDK, so even Share must also be added to the system library), click the project name – Target – Link – BuildPhases – Binary With Libraries – click on the + library search system you need, and add
Libicucore.dylib (PS, here, because maybe your Xcode is Xcode7, so the.Dylib here might display.Tbd in your system library), just add it normally
ImageIO.framework (shareSDK Sina must rely on libraries)
AdSupport.framework (shareSDK Sina must rely on libraries)
2. configuration engineering URL Types in URL Schemes,
This URL Schemes is used to tune the identity of the third party client after payment or share or authorization to go back to your program
Method: click the project name – Target – Info – URL Types – click + number, fill in the URL Schemes column in the second step to get the APPID (see figure for the previous step, find the info tab yourself)
3 if the Xcode7 needs to join the LSApplicationQueriesSchemes field in the Info.Plist file, the Array type, then add two small options inside, respectively Weixin and wechat (Xcode7http request Xcode7 adaptation problems please Baidu)
Sixth. Start writing code!
1. copy the WXPay folder in the Demo to the project folder, and then Add to the project directory
2. in AppDelegate.h, the #import correlation header file, the application: (UIApplication *) applicationdidFinishLaunchingWithOptions: (NSDictionary *) launchOptions in the AppDelegate.m file
Add [WXApi, registerApp:APP_ID, withDescription:@, demo, 2 in the method; (here APPID is the second step you get APPID, generally recommended macro. The @ demo2.0 ‘doesn’t need to be modified), my demo has also registered shareSDK in this method. I hope you don’t have any doubts.
3. add these two methods in AppDelegate.m:
/ / important updates, two IOS9.0 after being abandoned, so if you are Xcode7.2, may appear onResp callback method can not enter the WeChat, the reason is the following two methods is not called, so this update, use another method (should not delete these two methods, a new method is the 9 method, after the low version of the system does not support users. So I have three ways to stay, if someone found can not stay, Jane please tell me, thanks again
– – (BOOL) application: (UIApplication *), application, handleOpenURL: (NSURL *) url;
– – (BOOL) application: (UIApplication *), application, openURL: (NSURL *), URL, sourceApplication: (NSString *), sourceApplication, annotation: (ID), annotation;
By the method of / / – (BOOL) application: (UIApplication * APP) openURL: (NSURL *) URL options: (NSDictionary*) options;
How to write code in specific methods, see the notes in Demo.
4. after configuring the AppDelegate file, copy your project into the UIViewController+WeChatAndAliPayMethod category in Demo, and Add to the project,
Refer to this category on the page where you need payment. (see the ViewController pages, methods, and code for Demo, and review the annotations and understand the code carefully. The integration of WeChat’s payment is complete)
Alipay and WeChat PS. integrated payment integration is similar, if you integrate WeChat to pay, you will find Alipay integration more simple.
The first step will copy Alipay to pay SDK to the project folder, and then Add to the project directory,
(Ps. Take note of this, AliPay, ThirdParty in demo, and those files are what you need to copy at this step
Especially OpenSSL and Util, and those two.A files. Because Alipay’s development document writing is really bad, out of order, not directly to you to add the SDK package, these things are drawn from the official demo. Specifically, you can download the official demo to have a look.
The second step, after the Add is finished with the SDK package, introduces the required system library. Calls to the UIViewController+WeChatAndAliPayMethod in the category of Alipay payment method. (pay attention to the code and comments in my Demo)
PS. If you may encounter when < integrated Alipay; openssl/xxx.h> not found (error, you usually use other SDK may also encounter), the general situation is Xcode can not find the path of these documents. Here, you can add the path of OpenSSL to the Header Search Paths tab in the BuildSettings in Targets.
Key point: there are two files that contain several key macros in Demo, payRequsesrHandler.h and AliPayNeedDEF.h. The contents of these two files should be filled in by your own data. Specifically how to get these data, my notes written clear. Just take a closer look.
Also, when you call the method in my payment category, write a monitor to notify you of the success of the payment. This is clearly written in my code notes, and there is no more detail here.
the next section is the later additions. (three party login and share with three parties, including adapter ios9)
Note: three party login and share the code, Mob official website has, will not repeat the details. Here is mainly to reduce the amount of code, and enhance the reusability of some integration. If there are any problems or improper handling, I hope the friends will actively put forward.
First of all, if you can do three party login, and payment, you need to register on the third party platform application, with login rights.
Secondly, after the XCode7, IOS9, shareSDK corresponding changes also, third parties share login time, need to be more than before, some steps, such as adding Schemes white list:
You need to add so many fields in info.plist (to accommodate the new SSO license). The following are only the fields that sina, micro-blog, QQ, WeChat, three platforms need to add
adds elements in the LSApplicationQueriesSchemes array field
To make it easy for you to add on demand, here is the classification:
Sina micro-blog: sinaweibo,
Weibosdk, (adding weibosdk needed)
Weibosdk2.5 (added weibosdk required)
(the following is QQZone need to add, but in general, need to integrate QQ share login, all need QQZone, so it is generally recommended that we directly add QQ and QQzone into)
Also, don’t forget the settings inside the URLType. (QQ needs sixteen decimal conversion when added. Example: QQ41D9BC03)
Simple collation of login:
I have a LoginMethodObject folder in my demo project, with a new class of my own, LoginMethod.
Users only need to reference this class to instantiate an object. And realize the agent
– – (void) recieveTheUserInfo: (NSDictionary*) userInfo
ErrorMsg: (NSString *) errorMsg;
UserInfo is the acquired user information. Inside, I only got simple information about nicknames, uid, avatar, and so on. Special treatment is needed if additional information is needed. However, general login only need uid is enough, so here, but more details.
Note: in order to implement this agent, the logic is clearer for convenience. We need to make a judgment, that is, to determine whether errorMsg exists.
(like AFNetWorking), if errorMsg exists, it explains the failure to get, and errorMsg print out is the wrong reason. If errorMsg does not exist, representing the access success, you can use the user information in userInfo directly
Specifically, we can see the use of demo in LoginViewController.
About third parties sharing:
Third party share, Mob’s official website to write very clear that I will not make an unnecessary move to write what. Demo has a model, and if you don’t want to go to mob, you can just copy it directly.
(to put it simply, what demo says is a way to send the same content for all platforms. If you need to share different content for different platforms, you need to call another method, as follows
code calls for sharing different content on different platforms