Files
tysdk-intergration/sdk-intergration/Packages/tysdk/Plugins/iOS/TYSDKInterface.mm
2024-08-08 20:53:34 +08:00

208 lines
8.0 KiB
Plaintext

#import <Foundation/Foundation.h>
#import <XYSDK/XYSDK.h>
#define TOKEN_ERROR @"-8"
extern "C" {
NSString* DicTojsonString(NSDictionary *dict)
{
try {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingFragmentsAllowed error:&error];
NSString *jsonString;
if (!jsonData) {
NSLog(@"%@",error);
} else {
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
return mutStr;
} catch (NSException *exception) {
return @"";
}
}
void ProcessLoginResult(XYResp *resp)
{
NSMutableDictionary *resultDict = [@{} mutableCopy];
[resultDict setValue:[NSString stringWithFormat:@"%ld", (long)resp.errCode] forKey:@"code"];
[resultDict setValue:resp.errStr ? resp.errStr : @"" forKey:@"errStr"];
if(resp.errCode == XYSuccess){
[resultDict setValue:resp.respObj forKey:@"respObj"];
}
NSString *result = DicTojsonString(resultDict);
const char* param = AllocCString(result);
UnitySendMessage("TYSdkFacade","LoginResult", param);
}
//更新登录支付域名
void UnityResetServerUrl(const char* url)
{
NSString* serverUrl = [[NSString alloc] initWithCString:url encoding:NSUTF8StringEncoding];
NSLog(@"TYSdkInterface UnityResetServerUrl %@", serverUrl);
if(serverUrl != nil && ![serverUrl isEqualToString:@""])
{
[XYApi resetServerUrlString:serverUrl];
}
}
//登录
void UnityLoginByTokenFun(const char* ctoken)
{
NSLog(@"TYSdkInterface UnityLoginByTokenFun %s", ctoken);
NSString* token = [[NSString alloc] initWithCString:ctoken encoding:NSUTF8StringEncoding];
if(token != nil && ![token isEqualToString:@""])
{
[XYApi XYLoginByToken:token completionHandler:^(XYResp *resp) {
NSLog(@"TYSdkInterface UnityLoginByTokenFun %ld, %@, %@", (long)resp.errCode, resp.respObj, resp.errStr);
ProcessLoginResult(resp);
}];
}else{
NSMutableDictionary *resultDict = [@{} mutableCopy];
[resultDict setValue:TOKEN_ERROR forKey:@"code"];
[resultDict setValue:@"" forKey:@"errStr"];
NSString *result = DicTojsonString(resultDict);
const char* param = AllocCString(result);
UnitySendMessage("TYSdkFacade","LoginResult", param);
}
}
void UnityLoginByGuest()
{
XYLoginReq *req = [XYLoginReq initWithLoginType:XYLoginWithGuest];
[XYApi XYLoginWith:req completionHandler:^(XYResp * _Nonnull resp) {
NSLog(@"TYSdkInterface UnityLoginByGuest: %@", resp);
ProcessLoginResult(resp);
}];
}
void UnityLoginByGoogle()
{
XYLoginReq *req = [XYLoginReq initWithLoginType:XYLoginWithGoogle];
[XYApi XYLoginWith:req completionHandler:^(XYResp * _Nonnull resp) {
NSLog(@"TYSdkInterface UnityLoginByGoogle: %@", resp);
ProcessLoginResult(resp);
}];
}
void UnityLoginByFacebook()
{
XYLoginReq *req = [XYLoginReq initWithLoginType:XYLoginWithFB];
[XYApi XYLoginWith:req completionHandler:^(XYResp * _Nonnull resp) {
NSLog(@"TYSdkInterface UnityLoginByFB: %@", resp);
ProcessLoginResult(resp);
}];
}
void UnityGetIdentityFun(const char* type)
{
}
void UnityLoginOut()
{
NSLog(@"TYSdkInterface UnityLoginOut");
[XYApi XYLogoutWithCompletion:^(XYResp * _Nonnull resp) {
if(resp.errCode == XYSuccess)
{
NSLog(@"TYSdkInterface UnityLoginOut Success");
NSLog(@"%@", resp.respObj);
}
else
{
NSLog(@"TYSdkInterface UnityLoginOut Faild");
NSLog(@"Error Code:%ld msg:%@", resp.errCode, resp.errStr);
}
}];
}
//支付
void UnityKnow(const char* userId,const char* productId,const char* productPrice,const char* productName,const char* productCount,const char* orderid,const char* appinfo)
{
NSLog(@"TYSdkInterface UnityKnow ");
NSString* pUserId = [[NSString alloc] initWithCString:userId encoding:NSUTF8StringEncoding];
NSString* porderid = [[NSString alloc] initWithCString:orderid encoding:NSUTF8StringEncoding];
NSString* pProductId = [[NSString alloc] initWithCString:productId encoding:NSUTF8StringEncoding];
NSString* pProductPrice = [[NSString alloc] initWithCString:productPrice encoding:NSUTF8StringEncoding];
NSString* pProductName = [[NSString alloc] initWithCString:productName encoding:NSUTF8StringEncoding];
NSString* pProductCount = [[NSString alloc] initWithCString:productCount encoding:NSUTF8StringEncoding];
NSString* pAppInfo = [[NSString alloc] initWithCString:appinfo encoding:NSUTF8StringEncoding];
XYProduct* product = [XYProduct createShoppingDataWith:XYOnlyConsume];
if (porderid != NULL && porderid.length > 0) {
product.productOrderId = porderid;
}
[product XYProductWithAppInfo:pAppInfo productId:pProductId productName:pProductName productPrice:[pProductPrice floatValue] gameId:-1 productCount:[pProductCount integerValue] userId:[pUserId integerValue]];
[XYApi XYCharge:product completionHandler:^(XYResp * _Nonnull resp) {
NSMutableDictionary *resultDict = [@{} mutableCopy];
[resultDict setValue:[NSString stringWithFormat:@"%ld", (long)resp.errCode] forKey:@"code"];
[resultDict setValue:resp.errStr ? resp.errStr : @"" forKey:@"errStr"];
NSString *result = DicTojsonString(resultDict);
const char* param = AllocCString(result);
UnitySendMessage("TYSdkFacade","PayResult", param);
}];
}
void GetSKUList()
{
NSLog(@"TYSdkInterface GetSKUList ");
[XYApi XYGetLocalProductPriceWithCompletion:^(XYResp * _Nonnull resp) {
NSMutableDictionary *resultDict = [@{} mutableCopy];
[resultDict setValue:[NSString stringWithFormat:@"%ld", (long)resp.errCode] forKey:@"code"];
if(resp.errCode == XYSuccess){
NSLog(@"TYSdkInterface GetSKUList Success");
NSLog(@"SKUList %@", resp.respObj);
[resultDict setValue:resp.respObj forKey:@"respObj"];
}
else
{
NSLog(@"TYSdkInterface GetSKUList Faild");
NSLog(@"SKUList %ld %@", resp.errCode, resp.errStr);
}
NSString *result = DicTojsonString(resultDict);
const char* param = AllocCString(result);
UnitySendMessage("TYSdkFacade","SKUListResult", param);
}];
}
//打点
void SetGaUserInfo(const char* userId)
{
}
void SetGaCommonInfo(const char* SetGaCommonInfo)
{
}
void GAReportParams(int type, const char* eventstr, const char* paramstr)
{
}
//广告相关
void UnitySetAdBoxUserInfo(char* userId)
{
}
void UnityInitADSConfig()
{
}
void UnityLoadRvADS()
{
}
void UnityShowRVAD()
{
}
}