///2016/12/03///
///by xbw
///xcode 8.1
只做了前端,也只能写前端的记录了。
注意framework的最低适用版本,最低使用版本大于app发布版本时,设置Required 为 Optional。
将工程的Build Settings中的Other Linker Flags添加-all_load设置。
这里有点问题,我们项目是cocos2d游戏,c++的,所以这里设置-ObjC
至此,工程配置完毕,可以进行支付代码的开发
商户签名用于验证商户的身份,属于附加安全措施。此组参量为选填参量,接入时可以不用填写。
付钱拉内部实现了默认签名,无需进行任何代码接入。
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();就会拉起支付并返回订单号。。。。 有问题留言。。。。。。
