After a merchant applies to develop an APP application on the WeChat Open Platform, the WeChat Open Platform will generate the APP's unique identifier, APPID. Open the project in Xcode and set URL Schemes in the project properties to your APPID. As shown in the picture.
2. Import WeChat Payment SDK
Copy the folder in the official demo to the project
Set the APPID in APPdelegate
Import dependent libraries
Click the payment button in the project and write the following method
Don’t forget to import the header file and follow the agent and register the agent?
info. Add the following field LSApplicationQueriesSchemes to the plist, which is of Array type, and then add two small options in it, namely weixin and wechat
Attention! ! ! The following three places? Must correspond? One less is essential
If there is no callback, write this in the APPdelegate
//The abandoned methods are as follows
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url {
return? [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}< /p>
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL: url delegate:[WXApiManager sharedManager]];
}
//New replacement method
- (BOOL)application:(UIApplication*)app openURL: (NSURL*)url options:(NSDictionary*)options {
return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}
/ /Launch WeChat Pay
PayReq* req? = [[PayReq alloc] init];
req.partnerId = @"1220277201";
req. prepayId? = @"9201039000160315ab9324b87b451223";
req.nonceStr? = @"83DB7tk21akNRSFs";
req.timeStamp = 1458027344;
req.package? = @"Sign=WXPay";
req.sign ? = @"db6919dbd8ccb3f8a25108bebcd87f7a02c52e39";
[WXApi sendReq:req];
// Get the current time
time_t now;
time(&now);
// timestamp
//NSString *timestamp = [NSString stringWithFormat: @"%ld", now];
// Random string
//NSString *nonceStr = [[self md5:timestamp] uppercaseString];
//Order id
NSString *prepayid =? _prepayid;
PayReq *request = [[PayReq alloc] init];
/** Merchant request Merchant ID applied for by Tenpay */
request.partnerId = WXPartnerid;
/** Prepayment order*/
request.prepayId= prepayid;
/** The data and signature filled in by the merchant based on the Tenpay document*/
request.package = @"Sign=WXPay";
/* * Random string, anti-retransmission*/
request.nonceStr= _noncestr;
/** Timestamp, anti-retransmission*/
request.timeStamp = [_timestamp intValue];
/** The merchant’s signature on the data based on the WeChat open platform document*/
request.sign= _sign;
/ *! @brief Send a request to WeChat and wait for WeChat to return onResp
*
* After the function is called, it will switch to the WeChat interface. The third-party application waits for WeChat to return onResp. WeChat will definitely call onResp after the asynchronous processing is completed. Supports the following types
* SendAuthReq, SendMessageToWXReq, PayReq, etc.
* @param req Specific sending request, please release it yourself after calling the function.
* @return Returns YES on success, NO on failure.
*/
[WXApi sendReq: request];