浏览代码

sdk-my-ios .mm

gdl_123 6 月之前
父节点
当前提交
ec2ed46ecc
共有 1 个文件被更改,包括 190 次插入0 次删除
  1. 190 0
      Build/BuildDependenceResource/Plugins/iOS/MianYou_SDK_IOS/QsdkMgr.mm

+ 190 - 0
Build/BuildDependenceResource/Plugins/iOS/MianYou_SDK_IOS/QsdkMgr.mm

@@ -0,0 +1,190 @@
+#import <Foundation/Foundation.h>
+
+@import OEGFramework;
+
+extern "C" 
+{
+    static  NSString* UnityListenerGoName;
+
+
+    void QSDK_SetListener(const char *gameObjectName){
+       UnityListenerGoName = QsdkCreateNSString(gameObjectName);
+    }
+
+
+    void SendMsgToUnity(NSString* messageName,messageName* parameters)
+    {
+
+        if (!UnityListenerGoName) {
+            NSLog(@"U3D not set listener");
+            return;
+        }
+        if ([parameters isKindOfClass:NSString.class] && [parameters length]) {
+            UnitySendMessage([UnityListenerGoName UTF8String], [messageName UTF8String], [parameters UTF8String]);
+        }
+        else{
+            UnitySendMessage([UnityListenerGoName UTF8String], [messageName UTF8String], "");
+        }
+    }
+
+    NSString* QsdkCreateNSString (const char* string)
+    {
+        if (string)
+            return [NSString stringWithUTF8String: string];
+        else
+            return [NSString stringWithUTF8String: ""];
+    }
+
+
+void QSDK_Init() {
+    
+    //SDK初始化 code: 0:成功, 1:失败
+    [[CrudeMingle share] InitEhuoia:^(int code, NSString * _Nonnull msg) {
+        NSLog(@"code=%d, msg=%@", code, msg);
+        if(code == 0)
+        {
+            SendMsgToUnity(@"onInitSuccess",@"Init:Init Success");
+        }
+        else
+        {
+            SendMsgToUnity(@"onInitSuccess",@"Fail");
+        }
+    }];
+
+}
+
+void QSDK_login() {
+
+    //使用SDK登录界面登录
+    [[CrudeMingle share] LoginEhuoiaWithCallback:^(int code, NSString * _Nonnull msg, NSString * _Nonnull sessionID, NSString * _Nonnull accountid, NSString * _Nonnull fbid, NSString * _Nonnull loginType) {
+        NSLog(@"code=%d, msg=%@, sessionID=%@, accountid=%@, loginType=%@", code, msg, sessionID, accountid, loginType);
+
+        if (code == 0)
+        {
+            SendMsgToUnity(@"onLoginSuccess",[NSString stringWithFormat:@"%d[]%@[]%@[]%@[]%@",code,msg, sessionID, accountid, loginType]);
+        }
+        else
+        {
+             SendMsgToUnity(@"onLoginFail",msg);
+        }
+    }];
+
+}
+
+void QSDK_Pay(const char *productId,const char *productName,const char * amount,const char *orderNo,
+                const char *callBackUrl,const char *extrasParams, 
+                const char * gameName,const char * serverName,const char* productDesc) {
+    
+    //支付
+    [[CrudeMingle share] FuEhuoiaWithPrice:QsdkCreateNSString(amount)
+         GameName:QsdkCreateNSString(gameName)
+       ServerName:QsdkCreateNSString(serverName)
+    CustomOrderId:QsdkCreateNSString(orderNo)
+       CustomInfo:QsdkCreateNSString(extrasParams)
+        ProductId:QsdkCreateNSString(productId)
+      ProductDesc:QsdkCreateNSString(productDesc)
+      CallBackUrl:QsdkCreateNSString(callBackUrl) AndCallBack:^(int code, NSString * _Nonnull msg, NSString * _Nonnull orderID) {
+          
+          NSLog(@"支付回调:code=%d, msg=%@, orderID=%@", code, msg, orderID);
+        if (code == 0)
+        {
+            SendMsgToUnity(@"onPaySuccess",@"支付Suc");
+        }
+        else
+        {
+             SendMsgToUnity(@"onPayFail",@"");
+        }
+      }];
+    
+}
+
+void QSDK_logout() {
+    
+    //退出登录
+    if ([[CrudeMingle share] logout]) {
+        NSLog(@"退出登录成功");
+         SendMsgToUnity(@"onLogoutSuccess",@"");
+    };
+}
+
+}
+// 1. OEGActionType:
+// typedef enum {
+//     Register = 0,
+//     LoginOEGID,
+//     LoginFacebook,
+//     LoginGoogle,
+//     LoginApple,
+//     Playnow,
+//     Logout,
+//     Profile,
+//     ChangePassword,
+//     ForgotPassword,
+//     VerifyEmail,
+//     VerifyPhone,
+//     Close
+// }OEGActionType;
+void SDK_OEG_AccountCallback(OEGActionType type, id _Nullable response, BOOL success, NSError  * _Nullable error)
+{
+    if(error)
+    {
+        NSLog(@"error:%@",error);
+    }
+    else
+    {
+        if(type == OEGActionType.Logout)
+        {
+            if(success)
+            {
+                NSLog(@"退出登录成功");
+                SendMsgToUnity(@"onLogoutSuccess",@"");
+            }
+            return;
+        }
+
+        if(success)
+        {
+            NSString status = response[@"status"];
+            NSString token = response[@"token"];
+            NSString uuid = response[@"uuid"];
+            NSString message = response[@"message"];
+
+            if(status == @"success")
+            {
+                int code = 0;
+                SendMsgToUnity(@"onLoginSuccess",[NSString stringWithFormat:@"%d[]%@[]%@[]%@[]%@",code,message, token, uuid, "111"]);
+            }
+            else
+            {
+                SendMsgToUnity(@"onLoginFail",message);
+            }
+        }
+    }
+}
+
+// typedef enum {
+//         OEGPurchasing = 0,
+//         OEGPurchased, // Purchased with Apple and verify server error
+//         OEGRestored,
+//         OEGFailed,
+//         OEGRequestError, // Request Product ID error
+//         OEGVerified // Purchased with Apple and verify server success
+// }OEGIAPStatus;
+void SDK_OEG_Pay_IAPCallback(OEGIAPStatus status, NSString *message, NSError  * _Nullable error)
+{
+    if(error)
+    {
+          NSLog(@"error:%@",error);
+    }
+    else
+    {
+        if(status == OEGIAPStatus.OEGVerified)
+        {
+            SendMsgToUnity(@"onPaySuccess",@"支付Suc");
+        }
+        else
+        {
+             SendMsgToUnity(@"onPayFail",@"");
+        }
+    }
+}