国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development Detailed explanation of iOS WeChat payment development case code

Detailed explanation of iOS WeChat payment development case code

Mar 27, 2017 pm 01:30 PM
ios WeChat Pay

This article mainly introduces the iOS WeChat payment development case in detail, which has certain reference value. Interested friends can refer to

WeChat payment has many pitfalls, and the official documents are provided It is not comprehensive at all, and the demo is also "shy" and difficult to understand. Many of the details that were paid attention to were not reflected and many detours were taken. Therefore, the system development process is as follows. (The complete demo is attached at the end of the blog) This includes the compatibility processing of WeChat payment development and Alipay development calling client. (The two signatures are placed on the mobile side. The blog does not mention the situation of not installing the WeChat client. It is also very simple to judge by the return value of 0 when calling this method [WXApi sendReq:request].)

1. Environment configuration

1. First, https protocol access, set the whitelist in plist

Detailed explanation of iOS WeChat payment development case code

2. When you have For WeChat sharing, collection, payment, login, etc., you need to add the following code (LSApplicationQueriesSchemes) in "Info.plist"

Detailed explanation of iOS WeChat payment development case code

3. Solve the problem that bitcode cannot be compiled

Detailed explanation of iOS WeChat payment development case code

4. Set URL types

Detailed explanation of iOS WeChat payment development case code

5. Import SDK (can be transplanted from WeChat official demo)

Detailed explanation of iOS WeChat payment development case code

6. Import system dependency library

Detailed explanation of iOS WeChat payment development case code

7. Special attention should be paid to the fact that

WeChat payment is divided into points. Unit, that is to say, if your payment amount is kept to two decimal places, the payment amount must be *100 before being sent to the WeChat payment platform, and so on for the others.

2. Code development

1. Operations required at the program entrance (i.e. applegate.m)

Detailed explanation of iOS WeChat payment development case code

2. Add the following Proxy method, otherwise the WeChat customer service side will not be called back (also in the delegate.m file)

Detailed explanation of iOS WeChat payment development case code

3. The callback function for successful WeChat payment

This is necessary To explain, the official document explains this: The result of successful payment on the customer service side cannot be directly regarded as the result of successful payment of the order. It must be based on the order status returned by the server. In other words, after the payment on the customer service side is successful, WeChat Pay The platform will send a payment success message to the server, modify the order status in the background, and return it to the client. The simple thing is that if the payment is successful, a notification must be sent to a specific view controller (a view controller with WeChat payment function), so that this specific view control can request the status of the server order. This callback function must be written in delegate.m!!!

Detailed explanation of iOS WeChat payment development case code

4. Code for a specific view controller (view controller with WeChat payment function)
4.1 Submit a prepayment order to obtain the pre-order id (this process must be signed twice, namely without parameters and signature Carrying parameter signatures, of course, these methods have been encapsulated in the payRequsestHandler class, you only need to pass the parameters to call the method) This is also the action method of clicking the payment button

Detailed explanation of iOS WeChat payment development case code

4.2 Get the prepaid order, then you can adjust the customer service side of WeChat payment (4.2 and 4.1 codes are consecutive)

Detailed explanation of iOS WeChat payment development case code

Two independent packages with sign parameter signature Method, I did not use the method encapsulated by payRequsestHandler, I wrote it myself, because there was a problem after using it (the screenshot of the problem is as follows), take a screenshot of the code first, and then provide a code block that can be directly copied and pasted
Screenshot of the problem: (I believe many people have encountered this I have been here before, 100% it is a signature issue)

Detailed explanation of iOS WeChat payment development case code

Method one:

Detailed explanation of iOS WeChat payment development case code

Method two:

Detailed explanation of iOS WeChat payment development case code

4.3 The above code can completely solve the WeChat payment problem. The last step is left. The payment is successful and returns to the app to call the delegate's -(void)onResp:(BaseResp*)resp method. So here we need to send a notification to a specific view controller and let him request the background order status. What I want to explain here is that after you adjust WeChat Pay from that interface, you will still be in the same place when you return. It’s just that the callback method must be in the delegate, so a successful notification must be sent in the callback method. Then you need to listen to this notification in the method of the specific view controller's view that is about to appear, and then request the background order status. What needs to be noted here is that the dealloc method needs to be rewritten to remove the notification.

Detailed explanation of iOS WeChat payment development case code

3. Compatibility processing of proxy methods of Alipay and WeChat payment callback clients

Detailed explanation of iOS WeChat payment development case code

4. demo

Code for copy and paste (sign signature)

-(NSString?)createMD5SingForPay:(NSString?)appid_key?partnerid:(NSString)partnerid_key?prepayid:(NSString?)prepayid_key?package:(NSString?)package_key?noncestr:(NSString)noncestr_key?timestamp:(UInt32)timestamp_key?
{?
NSMutableDictionary?*signParams?=?[NSMutableDictionary?dictionary];?
[signParams?setObject:appid_key?forKey:@”appid”];?
[signParams?setObject:noncestr_key?forKey:@”noncestr”];?
[signParams?setObject:package_key?forKey:@”package”];?
[signParams?setObject:partnerid_key?forKey:@”partnerid”];?
[signParams?setObject:prepayid_key?forKey:@”prepayid”];?
[signParams?setObject:[NSString?stringWithFormat:@”%u”,(unsigned?int)timestamp_key]?forKey:@”timestamp”];
NSMutableString?*contentString?=[NSMutableString?string];?
NSArray?*keys?=?[signParams?allKeys];?
//按字母順序排序?
NSArray?*sortedArray?=?[keys?sortedArrayUsingComparator:^NSComparisonResult(id?obj1,?id?obj2)?{
return?[obj1?compare:obj2?options:NSNumericSearch];?
}];?
//拼接字符串?
for?(NSString?*categoryId?in?sortedArray)?{?
if?(?![[signParams?objectForKey:categoryId]?isEqualToString:@”“]?
&&?![[signParams?objectForKey:categoryId]?isEqualToString:@”sign”]?
&&?![[signParams?objectForKey:categoryId]?isEqualToString:@”key”]?
)?
{?
[contentString?appendFormat:@”%@=%@&”,?categoryId,?[signParams?objectForKey:categoryId]];
}?
}?
//添加商戶密鑰key字段?
[contentString?appendFormat:@”key=%@”,?@”這里填寫商戶密鑰”];?
NSString?*result?=?[self?md5:contentString];?
return?result;

}//創(chuàng)建發(fā)起支付時的sige簽名

-(NSString?)?md5:(NSString?)str?
{?
const?char?*cStr?=?[str?UTF8String];?
unsigned?char?result[16]=?“0123456789abcdef”;?
CC_MD5(cStr,?(CC_LONG)strlen(cStr),?result);?
//這里的x是小寫則產(chǎn)生的md5也是小寫,x是大寫則md5是大寫,這里只能用大寫,微信的大小寫驗證很逗?
return?[NSString?stringWithFormat:?
@”%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X”,?
result[0],?result[1],?result[2],?result[3],?
result[4],?result[5],?result[6],?result[7],?
result[8],?result[9],?result[10],?result[11],?
result[12],?result[13],?result[14],?result[15]?
];?
}//MD5?加密


The above is the detailed content of Detailed explanation of iOS WeChat payment development case code. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Jul 27, 2024 am 11:06 AM

Thanks to netizens Ji Yinkesi, xxx_x, fried tomatoes, Terrence, and spicy chicken drumsticks for submitting clues! According to news on July 27, Apple today re-released the iOS/iPadOS 18 Beta 4 update for developers. The internal version number was upgraded from 22A5316j to 22A5316k. It is currently unclear the difference between the two Beta 4 version updates. Registered developers can open the "Settings" app, enter the "Software Update" section, click the "Beta Update" option, and then toggle the iOS18/iPadOS18 Developer Beta settings to select the beta version. Downloading and installing the beta version requires an Apple ID associated with a developer account. Reported on July 24, iO

Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Aug 18, 2024 am 06:34 AM

Update: Saunders Tech has uploaded a tutorial to his YouTube channel (video embedded below) explaining how to install Fortnite and the Epic Games Store on an iPad outside the EU. However, not only does the process require specific beta versions of iO

Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Jul 31, 2024 pm 01:10 PM

According to news on July 31, Apple issued a press release yesterday (July 30), announcing the launch of a new open source Swift package (swift-homomorphic-encryption) for enabling homomorphic encryption in the Swift programming language. Note: Homomorphic Encryption (HE) refers to an encryption algorithm that satisfies the homomorphic operation properties of ciphertext. That is, after the data is homomorphically encrypted, specific calculations are performed on the ciphertext, and the obtained ciphertext calculation results are processed at the same time. The plaintext after state decryption is equivalent to directly performing the same calculation on the plaintext data, achieving the "invisibility" of the data. Homomorphic encryption technology can calculate encrypted data without leaking the underlying unencrypted data to the operation process.

Haqu K2 projector brings Olympic passion and dreams within reach Haqu K2 projector brings Olympic passion and dreams within reach Jul 24, 2024 pm 01:34 PM

In the just-concluded European Cup final, did you cheer crazily for the team you supported? In the upcoming Paris Olympics, are you also looking forward to perfectly capturing the highlight moments of each event? Among them, having a high-quality viewing equipment is crucial. The Haqu K2 projector is well-deserved to be a good choice for watching games due to its high cost performance and excellent performance. It not only has high brightness and clear picture quality, but also provides an immersive viewing experience, making every exciting moment of the game feel as if it is close at hand. Are you already attracted by such a device? It will definitely allow you to enjoy the passion and dreams of the Olympic Games at home. The most intimate highlight of Haqu K2 is its 210° super angle adjustment, which makes it convenient to watch movies whether on the ceiling or on the wall.

Apple iOS 18 and iPadOS 18 public beta version Beta 2 update released Apple iOS 18 and iPadOS 18 public beta version Beta 2 update released Jul 30, 2024 pm 04:19 PM

Thanks to netizens Mo 6_, Uh-huh-huh-huh, Cat-Eating Salted Fish, Yaochi Qinglian, Spicy Chicken Leg Burger, Siyan, and Tim Apple for submitting clues! According to news on July 30, Apple today launched the iOS18 and iPadOS18 public beta version Beta2 version update for iPhone and iPad users, two weeks after the last public beta version. The update content of this public beta version is similar to the developer preview version Beta4, with new CarPlay wallpapers, combing setting options, enhanced camera control, dark/light mode icons, etc. For details, please refer to the previous detailed reports. ##How to upgrade iOS/iPadOS/watchOS/macOS development version and public beta version? iOS/iPadOS upgrade iOS/iPa

Apple iPhone 16 is no longer pre-installed with Apple Intelligence Apple iPhone 16 is no longer pre-installed with Apple Intelligence Jul 30, 2024 pm 01:18 PM

According to industry insider Mark Gurman, Apple’s Apple Intelligence will be postponed to October. In other words, it will be pushed first on iOS18.1. Apple iPhone 16 is expected to be released in September, so Apple Intelligence will not be pre-installed. 1. Apple Intelligence Apple Intelligence is a personal intelligence system that uses a powerful generative model to provide new functions for iPhone, iPad and Mac to assist users in communicating, working and expressing. 2. Natural language understanding The large model embedded in Apple Intelligence has a deep understanding of the meaning of language.

What is the difference between H5 page production and WeChat applets What is the difference between H5 page production and WeChat applets Apr 05, 2025 pm 11:51 PM

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

Apple releases iOS/iPadOS 16.7.9 and 15.8.3 updates to older iPhones/iPads: fix security vulnerabilities Apple releases iOS/iPadOS 16.7.9 and 15.8.3 updates to older iPhones/iPads: fix security vulnerabilities Jul 30, 2024 am 10:13 AM

Thanks to netizen Ji Yinkesi for submitting the clue! According to news on July 30, Apple today released the first developer beta version of iOS/iPadOS 18.1 and the second public beta version of iOS/iPadOS 18. It also released iOS 16.7.9 and iOS 15.8.3 updates for older iPhones. Apple wrote in the update logs for both versions: "This update provides important security fixes and is recommended for all users to install," but did not mention what was fixed. iOS16.7.9 Note: iOS16.7.9 is suitable for Apple iPhoneX, iPhone8 and iPhone8Plus. According to the document details disclosed by Apple, the above three models are expected to support

See all articles