///2016/12/03///
///by xbw
///xcode 8.1
只做了前端,也只能写前端的记录了。
接入步骤
第一步、库文件导入与工程配置
1. 下载并添加库文件
1)在付钱拉官网下载iOS SDK,里面包含 libs 和 FQTest 两个目录。FQTest 目录
下的是示例项目,你需要将 libs 目录下的文件添加到你的项目。
2)如果不需要某些通道,删除 libs/Channels 下的相应目录即可。
2. 添加依赖 Frameworks
1) 依赖库
MessageUI.framework LocalAuthentication.framework MobileCoreServices.framework CoreMotion.framework CoreTelephony.framework libsqlite3.0.tbd libz.tbd libc++.tbd SystemConfiguration.framework CFNetwork.framework PassKit.framework
2) 说明
注意framework的最低适用版本,最低使用版本大于app发布版本时,设置Required 为 Optional。
3. 添加 URL Schemes
在 Xcode 中,选择你的工程设置项,选中 TARGETS 一栏,在 Info 标签栏的
URL Types 添加 URL Schemes。
1)微信支付:填入微信平台上注册的应用程序 id(为 wx 开头的字符串);
2)其它支付:则使用付钱拉分配的appid(如果长度大于15,取后15位);
4. 设置工程的工程的Build Settings
将工程的Build Settings中的Other Linker Flags添加-all_load设置。
这里有点问题,我们项目是cocos2d游戏,c++的,所以这里设置-ObjC
5. 如有必要设置info.plist允许http网络连接
6. 设置info.plist LSApplicationQueriesSchemes
LSApplicationQueriesSchemes
<array>
<string>weixin</string>
<string>wechat</string>
<string>alipay</string>
<string>alipayshare</string>
</array>
至此,工程配置完毕,可以进行支付代码的开发
第二步、付钱拉支付代码接入
1. 代码接入
//付钱拉SDK入口
FuqianlaPay *manager = [FuqianlaPay sharedPayManager];
//交易参量设置
manager.transactionParams =
@{
@"app_id":@"appdcd3fafe632346a8beabed17356d1ce8",
@"order_no":[self formatOrderId],
//@"pmtTp":@"22",//打开则使用app的支付通道选择界面
@"amount":@"0.01",
@"subject":@"商品标题",
@"body":@"商品描述",
@"notify_url":@"http://10.100.140.124:8081/adapter-client/receive/notify.htm",
};
//附带交易数据设置,只有易宝和京东需要
manager.payExtraParams = ^(CEPayType payType){
NSMutableDictionary * extra = [NSMutableDictionary dictionary];
if(payType == kPTJDPay)
{
if(0)//app传入的京东支付token
{
[extra setObject:@"nt06733722199928c0b6c422e6686855" forKey:@"token"];
}
}
return extra;
};
//支付结果
manager.payStatusCallBack = ^(CEPaymentStatus payStatus, NSString *result){
//如果京东支付切支付成功,保存京东支付token,以便下一次快捷支付
if(manager.payType == kPTJDPay && payStatus == kCEPayResultSuccess)
{
id token = [FuqianlaPay sharedPayManager].callCackParams;
}
};
//开始支付
[manager startPayAction];
//AppDelegate支付回调接入
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[FuqianlaPay handlePayCallBackUrl:url];
return YES;
}
2. 商户签名
商户签名用于验证商户的身份,属于附加安全措施。此组参量为选填参量,接入时可以不用填写。
1) 无签名:
付钱拉内部实现了默认签名,无需进行任何代码接入。
2) md5签名:
manager.signType = @"md5"; manager.merchMd5Key = @"c9840c899be3ae70892e588c402e22a4";
3) RSA签名:
manager.signType = @"rsa"; manager.rsaKeyPath = [[NSBundle mainBundle] pathForResource:@"private_key" ofType:@"p12"]; manager.rsaKeyPassword = @"123456";
第三步、参量说明
1. 支付请求参量
参数 | 参数名称 | 长度 | 是否必填 |
---|---|---|---|
app_id | 一秒支付分配给商户的应用id | 32 | 是 |
order_no | 订单号 | 32 | 是 |
amount | 金额 单位元 | 11 | 是 |
notify_url | 支付完成以后用于接受通知的商户服务器地址。 | 255 | 是 |
subject | 商品名称 | 255 | 是 |
body | 商品描述 | 255 | 否 |
pmtTp | 支付通道类型;默认使用付钱拉收银台; | 2 | 否 |
2. 支付通道参量pmtTp
通道名称 | 通道参量 |
---|---|
微信支付 | kPTWeixinPay |
支付宝支付 | kPTAlipay |
百度支付 | kPTBaiduPay |
银联支付 | kPTUPPay |
京东支付 | kPTJDPay |
易宝支付 | kPTYibaoPay |
Apple pay | kPTApplePay |
3. 支付状态
状态 | 状态说明 |
---|---|
kCEPayResultSuccess | 支付成功 |
kCEPayResultFail | 支付失败 |
kCEPayResultProcessing | 支付处理中 |
kCEPayResultCancel | 支付取消 |
kCEPayResultParamError | 参量错误 |
kCEPayResultUnknow | 其它错误 |
GameHelper.h
//
// GameHelper.h
// DaFuHao
//
// Created by 许博文 on 2016/11/4.
//
//
#ifndef GameHelper_h
#define GameHelper_h
#endif /* GameHelper_h */
class GameHelper : private cocos2d::Application{
public:
void static openURL(const char * url);
void static openPay();
std::string static openView();
};
GameHelper.mm
#include "GameHelper.h"
#import "FuqianlaPay.h"
#import "AppController.h"
#import "RootViewController.h"
#import "ViewController.h"
void GameHelper::openURL(const char *url){//跳转safari浏览器
NSString *strUrl = [NSString stringWithUTF8String:url];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:strUrl]];
}
void GameHelper::openPay(){//付钱啦支付代码
FuqianlaPay *manager = [FuqianlaPay sharedPayManager];
manager.showPayStatusView = YES;
manager.transactionParams =
@{
@"app_id":@"************",//商户id
@"order_no":@"123456789",//订单号
//@"pmtTp":@"22",//打开则使用app的支付通道选择界面
@"amount":@"0.01",//金额
@"subject":@"大富豪金币购买",
@"body":@"购买金币100个",
@"notify_url":@"http://10.100.140.124:8081/adapter-client/receive/notify.htm", //回调地址
};
[manager startPayAction];
}
std::string GameHelper::openView(){ //cocos2d带参数跳转ios原生界面,参数为订单号
//订单号产生
int kNumber = 15;
NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSMutableString *resultStr = [[NSMutableString alloc] init];
srand((unsigned)time(0));
for (int i = 0; i < kNumber; i++)
{
unsigned index = rand() % [sourceStr length];
NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
[resultStr appendString:oneStr];
}
//viewcontroller跳转
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
@"Main" bundle:[NSBundle mainBundle]];
ViewController *myController = [storyboard instantiateViewControllerWithIdentifier:@"mains"];
//订单号传值
myController.dingdan=resultStr;
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:myController animated:YES];
//订单号回调
return [resultStr cStringUsingEncoding:[NSString defaultCStringEncoding]];
}
ViewController.h
//
// ViewController.h
// FQTest
//
// Created by zzf073 on 16/4/27.
// Copyright © 2016年 zzf073. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
//订单号,viewcontroller传值
@property(retain,nonatomic) NSString* dingdan;
@end
ViewController.m
//
// ViewController.m
//
//
// Created by xbw on 16/11/04.
// Copyright © 2016年 xbw. All rights reserved.
//
#import "ViewController.h"
#import "FuqianlaPay.h"
@interface ViewController ()
@property (retain, nonatomic) IBOutlet UIButton *button;
@property (retain, nonatomic) IBOutlet UIButton *btnreturn;
@property (retain, nonatomic) IBOutlet UITextField *textfield;
@end
@implementation ViewController
- (IBAction)butre:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)but:(id)sender {
NSString *str = _textfield.text;
//输入金额字符转整型
NSInteger jb = [str integerValue];
//正则匹配整数
NSString *pattern = @"[1-9]\\d*";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: pattern options: nil error: &error];
NSArray *match = [regex matchesInString: str options: NSMatchingCompleted range: NSMakeRange(0, [str length])];
//是正整数
if(match.count != 0){
if (jb>=1) {
//金币比例1:100
NSString *jinbi = [NSString stringWithFormat:@"%@%ld%@", @"充值金币",jb*100,@"个" ];
FuqianlaPay *manager = [FuqianlaPay sharedPayManager];
manager.showPayStatusView = YES;
manager.transactionParams =
@{
@"app_id":@"商户id",
@"order_no":_dingdan,
//@"pmtTp":@"22",//打开则使用app的支付通道选择界面
@"amount":[NSString stringWithFormat: @"%ld",jb],
@"subject":@"大富豪金币充值",
@"body":jinbi,
@"notify_url":@"回调地址",
};
[manager startPayAction];
}else{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"出问题了" message:@"充值金额要多于10元哦" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alter show];
}
}else{
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"出问题了" message:@"只能输入整数金额" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alter show];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_button release];
[_btnreturn release];
[_textfield release];
[super dealloc];
}
@end
Main.storyboard新建
忘记cocos2d调用支付了。
在cocos2d里的按钮里写调用函数
GameHelper::openView();就会拉起支付并返回订单号。。。。
有问题留言。。。。。。