QsdkMgr.mm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #import <Foundation/Foundation.h>
  2. @import OEGFramework;
  3. extern "C"
  4. {
  5. static NSString* UnityListenerGoName;
  6. void QSDK_SetListener(const char *gameObjectName){
  7. UnityListenerGoName = QsdkCreateNSString(gameObjectName);
  8. }
  9. void SendMsgToUnity(NSString* messageName,messageName* parameters)
  10. {
  11. if (!UnityListenerGoName) {
  12. NSLog(@"U3D not set listener");
  13. return;
  14. }
  15. if ([parameters isKindOfClass:NSString.class] && [parameters length]) {
  16. UnitySendMessage([UnityListenerGoName UTF8String], [messageName UTF8String], [parameters UTF8String]);
  17. }
  18. else{
  19. UnitySendMessage([UnityListenerGoName UTF8String], [messageName UTF8String], "");
  20. }
  21. }
  22. NSString* QsdkCreateNSString (const char* string)
  23. {
  24. if (string)
  25. return [NSString stringWithUTF8String: string];
  26. else
  27. return [NSString stringWithUTF8String: ""];
  28. }
  29. void QSDK_Init() {
  30. //SDK初始化 code: 0:成功, 1:失败
  31. [[CrudeMingle share] InitEhuoia:^(int code, NSString * _Nonnull msg) {
  32. NSLog(@"code=%d, msg=%@", code, msg);
  33. if(code == 0)
  34. {
  35. SendMsgToUnity(@"onInitSuccess",@"Init:Init Success");
  36. }
  37. else
  38. {
  39. SendMsgToUnity(@"onInitSuccess",@"Fail");
  40. }
  41. }];
  42. }
  43. void QSDK_login() {
  44. //使用SDK登录界面登录
  45. [[CrudeMingle share] LoginEhuoiaWithCallback:^(int code, NSString * _Nonnull msg, NSString * _Nonnull sessionID, NSString * _Nonnull accountid, NSString * _Nonnull fbid, NSString * _Nonnull loginType) {
  46. NSLog(@"code=%d, msg=%@, sessionID=%@, accountid=%@, loginType=%@", code, msg, sessionID, accountid, loginType);
  47. if (code == 0)
  48. {
  49. SendMsgToUnity(@"onLoginSuccess",[NSString stringWithFormat:@"%d[]%@[]%@[]%@[]%@",code,msg, sessionID, accountid, loginType]);
  50. }
  51. else
  52. {
  53. SendMsgToUnity(@"onLoginFail",msg);
  54. }
  55. }];
  56. }
  57. void QSDK_Pay(const char *productId,const char *productName,const char * amount,const char *orderNo,
  58. const char *callBackUrl,const char *extrasParams,
  59. const char * gameName,const char * serverName,const char* productDesc) {
  60. //支付
  61. [[CrudeMingle share] FuEhuoiaWithPrice:QsdkCreateNSString(amount)
  62. GameName:QsdkCreateNSString(gameName)
  63. ServerName:QsdkCreateNSString(serverName)
  64. CustomOrderId:QsdkCreateNSString(orderNo)
  65. CustomInfo:QsdkCreateNSString(extrasParams)
  66. ProductId:QsdkCreateNSString(productId)
  67. ProductDesc:QsdkCreateNSString(productDesc)
  68. CallBackUrl:QsdkCreateNSString(callBackUrl) AndCallBack:^(int code, NSString * _Nonnull msg, NSString * _Nonnull orderID) {
  69. NSLog(@"支付回调:code=%d, msg=%@, orderID=%@", code, msg, orderID);
  70. if (code == 0)
  71. {
  72. SendMsgToUnity(@"onPaySuccess",@"支付Suc");
  73. }
  74. else
  75. {
  76. SendMsgToUnity(@"onPayFail",@"");
  77. }
  78. }];
  79. }
  80. void QSDK_logout() {
  81. //退出登录
  82. if ([[CrudeMingle share] logout]) {
  83. NSLog(@"退出登录成功");
  84. SendMsgToUnity(@"onLogoutSuccess",@"");
  85. };
  86. }
  87. }
  88. // 1. OEGActionType:
  89. // typedef enum {
  90. // Register = 0,
  91. // LoginOEGID,
  92. // LoginFacebook,
  93. // LoginGoogle,
  94. // LoginApple,
  95. // Playnow,
  96. // Logout,
  97. // Profile,
  98. // ChangePassword,
  99. // ForgotPassword,
  100. // VerifyEmail,
  101. // VerifyPhone,
  102. // Close
  103. // }OEGActionType;
  104. void SDK_OEG_AccountCallback(OEGActionType type, id _Nullable response, BOOL success, NSError * _Nullable error)
  105. {
  106. if(error)
  107. {
  108. NSLog(@"error:%@",error);
  109. }
  110. else
  111. {
  112. if(type == OEGActionType.Logout)
  113. {
  114. if(success)
  115. {
  116. NSLog(@"退出登录成功");
  117. SendMsgToUnity(@"onLogoutSuccess",@"");
  118. }
  119. return;
  120. }
  121. if(success)
  122. {
  123. NSString status = response[@"status"];
  124. NSString token = response[@"token"];
  125. NSString uuid = response[@"uuid"];
  126. NSString message = response[@"message"];
  127. if(status == @"success")
  128. {
  129. int code = 0;
  130. SendMsgToUnity(@"onLoginSuccess",[NSString stringWithFormat:@"%d[]%@[]%@[]%@[]%@",code,message, token, uuid, "111"]);
  131. }
  132. else
  133. {
  134. SendMsgToUnity(@"onLoginFail",message);
  135. }
  136. }
  137. }
  138. }
  139. // typedef enum {
  140. // OEGPurchasing = 0,
  141. // OEGPurchased, // Purchased with Apple and verify server error
  142. // OEGRestored,
  143. // OEGFailed,
  144. // OEGRequestError, // Request Product ID error
  145. // OEGVerified // Purchased with Apple and verify server success
  146. // }OEGIAPStatus;
  147. void SDK_OEG_Pay_IAPCallback(OEGIAPStatus status, NSString *message, NSError * _Nullable error)
  148. {
  149. if(error)
  150. {
  151. NSLog(@"error:%@",error);
  152. }
  153. else
  154. {
  155. if(status == OEGIAPStatus.OEGVerified)
  156. {
  157. SendMsgToUnity(@"onPaySuccess",@"支付Suc");
  158. }
  159. else
  160. {
  161. SendMsgToUnity(@"onPayFail",@"");
  162. }
  163. }
  164. }