添加微信支付示例代码
parent
73f1ccc5fc
commit
97c42125ab
|
@ -48,6 +48,7 @@
|
|||
A8CE73522810F8C800965B7E /* FCQRCodeScanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCQRCodeScanViewController.h; sourceTree = "<group>"; };
|
||||
A8CE73542810F8C800965B7E /* FCQRScanView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FCQRScanView.m; sourceTree = "<group>"; };
|
||||
A8CE73552810F8C800965B7E /* FCQRScanView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FCQRScanView.h; sourceTree = "<group>"; };
|
||||
D6278645283CC38F001270F1 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = demo.entitlements; sourceTree = "<group>"; };
|
||||
FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo.debug.xcconfig"; path = "Target Support Files/Pods-demo/Pods-demo.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -84,6 +85,7 @@
|
|||
9DD565BB23EC45080011FC4A /* demo */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D6278645283CC38F001270F1 /* demo.entitlements */,
|
||||
A8CE734B2810F3B400965B7E /* Common */,
|
||||
9DD565BC23EC45080011FC4A /* AppDelegate.h */,
|
||||
9DD565BD23EC45080011FC4A /* AppDelegate.m */,
|
||||
|
@ -432,6 +434,7 @@
|
|||
baseConfigurationReference = FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = demo/demo.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = 9QCKYFU5M4;
|
||||
|
@ -454,6 +457,7 @@
|
|||
baseConfigurationReference = 3F2BFD149B6F799A303A07B3 /* Pods-demo.release.xcconfig */;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = demo/demo.entitlements;
|
||||
CODE_SIGN_IDENTITY = "iPhone Distribution";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
DEVELOPMENT_TEAM = 9QCKYFU5M4;
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
#import "MainViewController.h"
|
||||
#import "FINExtensionHelper.h"
|
||||
#import "FINDemoClientHelper.h"
|
||||
|
||||
#import <FinApplet/FinApplet.h>
|
||||
#import <WechatOpenSDK/WXApi.h>
|
||||
|
||||
@interface AppDelegate ()
|
||||
|
||||
|
@ -53,7 +51,7 @@
|
|||
|
||||
if ([bundleId isEqualToString:@"com.finogeeks.mop.finosprite"]) {
|
||||
// 该appID【wx85663af68a0cbbc8】绑定的应用为凡泰助手,若要生效,请修改BundleID为com.finogeeks.mop.finosprite
|
||||
[WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:@"https://www.finclip.com"];
|
||||
[WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:@"https://www.finclip.com/finosprite/"];
|
||||
}
|
||||
|
||||
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||
|
@ -67,10 +65,7 @@
|
|||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
|
||||
if ([url.scheme isEqualToString:@"wx85663af68a0cbbc8"]) {
|
||||
return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate> _Nullable)[FINExtensionHelper sharedHelper]];
|
||||
}
|
||||
return YES;
|
||||
return [WXApi handleOpenURL:url delegate:[FINExtensionHelper sharedHelper]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <WechatOpenSDK/WXApi.h>
|
||||
|
||||
@interface FINExtensionHelper : NSObject
|
||||
@interface FINExtensionHelper : NSObject<WXApiDelegate>
|
||||
|
||||
+ (instancetype)sharedHelper;
|
||||
|
||||
|
|
|
@ -44,31 +44,46 @@ static FINExtensionHelper *instance = nil;
|
|||
|
||||
// 注入自定义api
|
||||
- (void)registerCustomApis {
|
||||
[[FATClient sharedClient] registerExtensionApi:@"onNative" handle:^(id param, FATExtensionApiCallback callback) {
|
||||
[[FATClient sharedClient] registerExtensionApi:@"onNative" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
|
||||
NSString *inputText = @"床前明月光,疑是地上霜。举头望明月,低头思故乡。";
|
||||
callback(FATExtensionCodeSuccess, @{@"text":inputText});
|
||||
}];
|
||||
|
||||
[[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handle:^(id param, FATExtensionApiCallback callback) {
|
||||
[[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
|
||||
NSString *inputText = @"鹅鹅鹅,曲项向天歌,白毛浮绿水,红掌拨清波。";
|
||||
callback(FATExtensionCodeSuccess, @{@"text":inputText});
|
||||
}];
|
||||
|
||||
// 注入获取用户信息
|
||||
[[FATClient sharedClient] registerExtensionApi:@"getUserProfile" handle:^(id param, FATExtensionApiCallback callback) {
|
||||
[[FATClient sharedClient] registerExtensionApi:@"getUserProfile" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
|
||||
NSDictionary *userInfo = @{@"nickName":@"张三",@"avatarUrl":@"",@"gender":@1,@"country":@"中国",@"province":@"广东省",@"city":@"深圳",@"language":@"zh_CN"};
|
||||
NSDictionary *resDic = @{@"userInfo":userInfo};
|
||||
callback(FATExtensionCodeSuccess,resDic);
|
||||
}];
|
||||
// 注入登录方法
|
||||
[[FATClient sharedClient] registerExtensionApi:@"login" handle:^(id param, FATExtensionApiCallback callback) {
|
||||
[[FATClient sharedClient] registerExtensionApi:@"login" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
|
||||
// 处理小程序登录逻辑后,调用小程序回调
|
||||
// 登录成功回调示例
|
||||
NSString *wxid = appletInfo.wechatLoginInfo[@"wechatOriginId"];
|
||||
NSString *path = appletInfo.wechatLoginInfo[@"profileUrl"];
|
||||
BOOL canWXLogin = [WXApi isWXAppInstalled] && [wxid length] > 0 && [path length] > 0;
|
||||
if (canWXLogin) {
|
||||
self.callback = callback;
|
||||
WXLaunchMiniProgramReq *req = [WXLaunchMiniProgramReq object];
|
||||
req.userName = wxid;
|
||||
req.path = path;
|
||||
req.miniProgramType = WXMiniProgramTypeRelease;
|
||||
[WXApi sendReq:req completion:^(BOOL success) {
|
||||
NSLog(@"打开微信:%d", success);
|
||||
}];
|
||||
}
|
||||
else {
|
||||
callback(FATExtensionCodeSuccess,@{@"desc":@"登录成功"});
|
||||
}
|
||||
}];
|
||||
// 注入微信支付方法
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[FATClient sharedClient] registerExtensionApi:@"requestPayment" handle:^(id param, FATExtensionApiCallback callback) {
|
||||
[[FATClient sharedClient] registerExtensionApi:@"requestPayment" handler:^(FATAppletInfo *appletInfo, id param, FATExtensionApiCallback callback) {
|
||||
// 支付调用,调用结果通过回调通告小程序
|
||||
[weakSelf getTestPayment:callback];
|
||||
}];
|
||||
|
@ -133,28 +148,37 @@ static FINExtensionHelper *instance = nil;
|
|||
|
||||
}
|
||||
|
||||
//支付结果回调
|
||||
//微信结果回调
|
||||
- (void)onResp:(BaseResp *)resp {
|
||||
if ([resp isKindOfClass:[PayResp class]]) {
|
||||
PayResp *response = (PayResp*)resp;
|
||||
//response.errCode
|
||||
// WXSuccess = 0, /**< 成功 */
|
||||
// WXErrCodeCommon = -1, /**< 普通错误类型 */
|
||||
// WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */
|
||||
// WXErrCodeSentFail = -3, /**< 发送失败 */
|
||||
// WXErrCodeAuthDeny = -4, /**< 授权失败 */
|
||||
// WXErrCodeUnsupport = -5, /**< 微信不支持 */
|
||||
switch (response.errCode) {
|
||||
case WXSuccess:
|
||||
self.callback(FATExtensionCodeSuccess, nil);
|
||||
break;
|
||||
|
||||
default:
|
||||
FATExtensionCode code = FATExtensionCodeSuccess;
|
||||
if (resp.errCode != WXSuccess) {
|
||||
code = FATExtensionCodeFailure;
|
||||
}
|
||||
if ([resp isKindOfClass:[PayResp class]]) {//支付
|
||||
self.callback(code, nil);
|
||||
}
|
||||
else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {//打开小程序
|
||||
NSString *extMsg = ((WXLaunchMiniProgramResp *)resp).extMsg;
|
||||
if (extMsg.length <= 0) {
|
||||
self.callback(FATExtensionCodeFailure, nil);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
self.callback(code, [self dictionaryWithJsonString:extMsg]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
|
||||
if (jsonString == nil) return nil;
|
||||
|
||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *err;
|
||||
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
|
||||
if(err) {
|
||||
NSLog(@"json解析失败:%@",err);
|
||||
return nil;
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.developer.associated-domains</key>
|
||||
<array>
|
||||
<string>applinks:www.finclip.com</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
|
@ -4,7 +4,7 @@
|
|||
<array>
|
||||
<dict>
|
||||
<key>appId</key>
|
||||
<string>611cf17739245f000182fa40</string>
|
||||
<string>60d58080a2b11b0001c439a4</string>
|
||||
<key>title</key>
|
||||
<string>小程序微信登录&支付示例</string>
|
||||
<key>startParams</key>
|
||||
|
|
Loading…
Reference in New Issue