许可证 | Apache 2 |
发布最后发布 | 2017年12月 |
任玩堂联运iOS SDK
https
接口,测试环境下使用http
接口提交数据。AGJointOperationSDK-iOS使用HeaderDoc注释进行文档支持。
开发者无需单独查阅文档,直接通过Xcode就可以查看接口和类的相关信息,减少不必要的麻烦。
先来看看AGJointOperationSDK-iOS的接入步骤
pod 'AGJointOperationSDK'
pod install
或
pod update
注意:1.2.0版本增加了第三方登录,如果选择手动安装,需要在您的项目中手动配置shareSDK。建议使用pod安装
AGJointOperationSDK
。
下载整个项目,将frameworks文件夹里的3个文件夹添加到您的项目中。
添加系统库
MobileCoreServices.framework
SystemConfiguration.framework
AdSupport.framework
UIKit.framework
libsqlite3.tbd
libicucore.tbd
libz.tbd
libstdc++.tbd
JavaScriptCore.framework
。
将-ObjC
标志添加到Other Linker Flags。
设置Enable Bitcode
为No
配置QQ、微信、微博
info.plist
添加白名单
在不需使用该功能的地方添加
#import <AGJointOperationSDK/AGJointOperationSDK.h>
初始化
//默认为正式环境,NO为测试环境
[AGJointOperationSDK setProductionMode:NO];
//配置clentId, seceret 和 热云 appKey
[AGJointOperationSDK setClientId:@"你的client id" clientSecret:@"你的client secret"];
//配置shareSDK,不集成第三方登陆和分享可不配置。
[AGVendorShare registerAppWithShareAppId:@"shareAppId" WiboAppId:@"weiboAppId" andWeiboSecret:@"weiboSecret" weChatAppId:@"weChatId" andWeChatSecret:@"WeChatSecret" QQAppId:@"QQAppId" andQQSecret:@"QQSecret"];
//设置游戏屏幕方向
//竖屏游戏
[AGJointOperationSDK setSupportedInterfaceOrientations:UIInterfaceOrientationMaskPortrait];
//横屏游戏
[AGJointOperationSDK setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
显示登录界面
[AGUser showLoginUIWithAnimated:YES];
显示用户中心
[AGUser showUserCenterWithAnimated:YES];
退出登录
[AGUser logOutWithCompletionBlock:^(BOOL success, NSError * _Nonnull error) {
}];
内购
// 购买
[[AGPurchase sharedInstance] purchaseWithProductIdentifier:@"你的产品商品id"
callBackUrl:@"你的回调地址"
tradeId:@"你的订单号"
privateInfo:@{@"你的参数":@""}
amount:amount
viewController:self
success:^(SKPaymentTransaction *transaction) {
NSLog(@"购买成功");
} failure:^(NSError *error) {
NSLog(@"购买失败");
NSLog(@"%@", error);
}];
分享到新浪微博,需要将链接添加到分享内容中。如下所示,要分享的链接为 http://www.baidu.com
NSArray *items = @[
@(SSDKPlatformTypeQQ), //包含QQ,Qzone
@(SSDKPlatformTypeWechat), //包含微信好友,朋友圈
@(SSDKPlatformTypeSinaWeibo) //微博
];
[AGVendorShare sharedWithView:self.view
items:items
title:@"分享测试"
url:[NSURL URLWithString:@"http://www.baidu.com"]
contentText:@"分享内容http://www.baidu.com"
image:imageArray
completionBlock:^(AGShareStatus sharestatus, NSError *error) {
UIAlertView *alerView = [[UIAlertView alloc]initWithTitle:@"" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
switch (sharestatus) {
case AGShareStateSuccess:
[alerView setTitle:@"分享成功"];
[alerView show];
break;
case AGShareStateFail:
[alerView setTitle:@"分享失败"];
[alerView show];
case AGShareStateCancel:
[alerView setTitle:@"分享取消"];
[alerView show];
default:
break;
}
}];
###回调地址说明
用户完成支付后,SDK服务器会给开发商服务器发送POST回调,通知订单处理结果。开发商需要在执行内购时传入回调地址。
####回调参数说明:
名字 | 可选 | 说明 |
---|---|---|
trade_id | 否 | 开发商提交的订单号 |
appgame_order_id | 否 | 支付系统生成的订单号 |
amount | 否 | 交易金额,以"元"为单位 |
status | 否 | 订单支付状态:complete - 完成 failed - 失败 canceled - 已取消 |
time | 否 | 回调请求发起时间,Unix时间戳形式 |
provider | 否 | 支付渠道标识码,根据 CP 接入的渠道而异,目前苹果的标识码为Apple |
private_info | 是 | CP 在发起支付请求时,如果提供 private_info,则原值返回,如果未提供,则无此参数 |
sign | 否 | 通知请求签名,用于验证通知有效性。 |
开发商收到通知后,请处理支付结果,并返回字符串 "ok" 表示回调处理成功。
如果SDK服务器发送通知请求后,未得到 "ok" 响应,则会在一段时间内尝试重新发起请求。
尝试重发间隔为:1 分钟,2 分钟,10 分钟,30 分钟,1 小时,2 小时,4 小时,12 小时,24 小时,最多重发 9 次。
####如何生成签名(Sign)
将所有参数键值对(参数=值,不包含sign本身)按照参数名从小到大顺序排序,用 & 符号连接起来,计算出MD5值,再连接上开发商的APP Secret再次计算MD5值,即为签名值:
md5(md5("参数1=值1&参数2=值2")+秘钥)
###验证用户信息有效性
通过SDK客户端获取Access Token成功后,如果对安全要求较高,可以用它向SDK服务器请求用户资源来进行认证,示例如下:
GET https://passport.appgame.com/resource/userinfo?access_token=aKmsEfsLLmLDpJneSTmyykYYNe4jKiwvn20YAb6v
测试环境下请调用测试服务器接口:
GET http://passport.test.appgame.com/resource/userinfo?access_token=aKmsEfsLLmLDpJneSTmyykYYNe4jKiwvn20YAb6v
如果请求成功,服务器将返回类似如下格式的JSON数据:
{
"id":"1000",
"passport_id":"1000",
"username":"Fishdrowned",
"email":"[email protected]",
"mobile":"137XXXXXXXX",
"avatar": "http://avatar.static.appgame.com/uploads/avatar/4d/Z9/4cCx.png",
"nickname":"Fishdrowned",
"sex": 0,
"province": 1,
"province_name":"北京市",
"city": 2,
"city_name":"市区"
}
如果请求失败,服务器将返回类似如下格式的JSON数据:
{
"status":401,
"error":"unauthorized",
"error_message":"Access token is not valid"
}
[AGJointOperationSDK setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape]
。AGConstants.h
里面。