iOS初级开发学习笔记:微信充值
iOS 初级开发学习笔记:微信充值
注册 APPID 步骤1-3
步骤1:申请微信开放平台账号首先,我们需要申请微信开放平台账号。具体步骤如下:
* 登录微信公众平台( 点击「我的」菜单,选择「开发者中心」,然后点击「开始开发」按钮。
* 填写基本信息,包括公司名称、联系人姓名和电话等,然后点击「提交申请」按钮。
步骤2:获取 APPID微信开放平台会对你的申请进行审批,如果通过,你将获得一个唯一的APPID。具体步骤如下:
* 等待微信开放平台审批,通常需要几分钟时间。
* 如果审批通过,你将收到一条短信通知,提示你可以登录开发者中心查看APPID。
步骤3:在微信开放平台设置 APPID现在,我们需要在微信开放平台设置我们的APPID。具体步骤如下:
* 登录微信公众平台的开发者中心。
* 点击「基本信息」菜单,选择「APPID管理」,然后点击「添加新APPID」按钮。
* 填写APPID相关信息,包括APPID、应用名称和应用描述等,然后点击「保存」按钮。
在 AppDelegate.m 中导入微信 SDK在 AppDelegate.m 文件中,我们需要导入微信 SDK。具体步骤如下:
```objectivecimport "WXApi.h"
```
继承 WXApiDelegate我们还需要继承 WXApiDelegate 类,来接收微信 SDK 的回调消息。具体步骤如下:
```objectivec@interface AppDelegate : UIResponder
```
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加代码在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中,我们需要添加以下代码:
```objectivec- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//1.注册微信SDK [WXApi registerApp:@"YOUR_APPID"];
return YES;
}
```
在 - (void)applicationDidBecomeActive:(UIApplication *)application 中添加代码在 - (void)applicationDidBecomeActive:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused or suspended.
//2.微信SDK回调 [self handleOpenURL:[launchOptions objectForKey:LAUNCH_OPTIONS_URL_KEY]];
}
```
在 - (void)handleOpenURL:(NSURL *)url 中添加代码在 - (void)handleOpenURL:(NSURL *)url 方法中,我们需要添加以下代码:
```objectivec- (void)handleOpenURL:(NSURL *)url {
//3.微信SDK回调 if ([url.host isEqualToString:@"weixin://"]) {
[WXApi handleOpenURL:url delegate:self];
}
}
```
在 - (void)applicationWillResignActive:(UIApplication *)application 中添加代码在 - (void)applicationWillResignActive:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This is where you should degrade performance if necessary (otherwise known as "preparing for sleep").
//4.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)applicationDidEnterBackground:(UIApplication *)application 中添加代码在 - (void)applicationDidEnterBackground:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, or perform here other tasks that are necessary to save the application state.
//5.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)applicationWillTerminate:(UIApplication *)application 中添加代码在 - (void)applicationWillTerminate:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate.
//6.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)onResp:(BaseResp *)resp 中添加代码在 - (void)onResp:(BaseResp *)resp 方法中,我们需要添加以下代码:
```objectivec- (void)onResp:(BaseResp *)resp {
//7.微信SDK回调 switch (resp.errCode) {
case WXSuccess:
break;
default:
break;
}
}
```
在 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 中添加代码在 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 方法中,我们需要添加以下代码:
```objectivec- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
//8.微信SDK回调 return [WXApi handleOpenURL:url delegate:self];
}
```
在 - (void)applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加代码在 - (void)applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中,我们需要添加以下代码:
```objectivec- (void)applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//9.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加代码在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中,我们需要添加以下代码:
```objectivec- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//10.微信SDK回调 return [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)onReq:(BaseReq *)req 中添加代码在 - (void)onReq:(BaseReq *)req 方法中,我们需要添加以下代码:
```objectivec- (void)onReq:(BaseReq *)req {
//11.微信SDK回调 switch (req.type) {
case ReqType:
break;
default:
break;
}
}
```
在 - (void)applicationDidBecomeActive:(UIApplication *)application 中添加代码在 - (void)applicationDidBecomeActive:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationDidBecomeActive:(UIApplication *)application {
//12.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)applicationWillResignActive:(UIApplication *)application 中添加代码在 - (void)applicationWillResignActive:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationWillResignActive:(UIApplication *)application {
//13.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)applicationDidEnterBackground:(UIApplication *)application 中添加代码在 - (void)applicationDidEnterBackground:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationDidEnterBackground:(UIApplication *)application {
//14.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (void)applicationWillTerminate:(UIApplication *)application 中添加代码在 - (void)applicationWillTerminate:(UIApplication *)application 方法中,我们需要添加以下代码:
```objectivec- (void)applicationWillTerminate:(UIApplication *)application {
//15.微信SDK回调 [WXApi handleOpenURL:[NSURL URLWithString:@"weixin://"] delegate:self];
}
```
在 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 中添加代码在 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 方法中,我们需要添加以下代码:
```objectivec- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
//16.微信SDK回调 return [WXApi handleOpenURL:url delegate:self