PlatformWan17.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**
  2. 17玩 SDK
  3. */
  4. import Gamecfg from "../common/gameCfg";
  5. import { gameMethod } from "../common/gameMethod";
  6. import { PlayerLogin, PlayerLoginPram } from "../common/Xyc";
  7. import { SevBack } from "../common/Xys";
  8. import Config from "../Config";
  9. import { GameEvent, LoadEvent, PlatEvent } from "../data/const/EventConst";
  10. import { AD_VIDEO_KEY, ConstItem, GameErrCode, PayProductParam, ReportRoleType } from "../data/const/TypeConst";
  11. import GameDataCenter from "../data/GameDataCenter";
  12. import GameController from "../GameController";
  13. import UIHelp from "../logic/ui/UIHelp";
  14. import EventMng from "../manager/EventMng";
  15. import NativeManager from "../utils/NativeManager";
  16. import PlatformBase from "./PlatformBase";
  17. export default class PlatformWan17 extends PlatformBase {
  18. rewardVideo: any
  19. adId: string;
  20. constructor() {
  21. super()
  22. window["NativeNotify"] = {
  23. //native平台回调
  24. OnNativeNotify: function (eventType, eventDataString) {
  25. try {
  26. console.log("NativeNotify OnNativeNotify eventType:" + eventType + ",eventDataString:" + eventDataString);
  27. let dataDict = JSON.parse(eventDataString);
  28. if (eventType == "17WanLogin") { //17登录
  29. if (dataDict.status == "0") {
  30. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.75, "login")
  31. let params: PlayerLoginPram = {
  32. pid: Config.pid,
  33. param: [dataDict.accountid, dataDict.sessionid]
  34. }
  35. // if (dataDict.status != 0) {
  36. // GameDataCenter.plat.showErrDialog(GameErrCode.errPlatLogin)
  37. // return
  38. // }
  39. setTimeout(() => {
  40. GameController.network.send(PlayerLogin.url, params, (result: SevBack) => {
  41. console.log("后段验证返回", JSON.stringify(result))
  42. if (result.type != 1) {
  43. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  44. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  45. }
  46. return
  47. }
  48. EventMng.emit(LoadEvent.LOAD_PROGRESS, 1, "login")
  49. if (result.type == 1 && result.platBack) {
  50. GameDataCenter.plat.instance.openId = result.platBack.openid
  51. GameDataCenter.plat.instance.loginParams = [result.platBack.token]
  52. console.log("后端验证成功", GameDataCenter.plat.instance.openId)
  53. // // 加载广告组件
  54. //GameDataCenter.plat.instance.initRewardedVideoAd(AD_VIDEO_KEY.welChest)
  55. // 获取邀请者uuid
  56. let inviter = ""
  57. GameDataCenter.plat.instance.login(inviter)
  58. } else {
  59. console.log("PlayerLogin.url 返回数据异常")
  60. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  61. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  62. }
  63. }
  64. })
  65. }, 1000)
  66. } else if (dataDict.status == "1") {
  67. //玩家取消登录,显示登录按钮
  68. EventMng.emit(LoadEvent.SHOW_LOGIN_BTN)
  69. } else if (dataDict.status == "2") {
  70. //玩家注销,退出游戏
  71. GameDataCenter.plat.instance.restart()
  72. }
  73. else {
  74. GameDataCenter.plat.showErrDialog(GameErrCode.errPlatLogin)
  75. }
  76. } else if (eventType == "17WanPay") { //17支付
  77. if (dataDict.status == 0) {
  78. //充值成功
  79. if (Config.paySuccAdokId != null) {
  80. clearInterval(Config.paySuccAdokId)
  81. Config.paySuccAdokId = null
  82. }
  83. Config.paySuccAdokIndex = 0
  84. Config.paySuccAdokId = setInterval(() => {
  85. Config.paySuccAdokIndex++
  86. if (Config.paySuccAdokIndex >= 5) {
  87. clearInterval(Config.paySuccAdokId)
  88. Config.paySuccAdokId = null
  89. }
  90. GameDataCenter.time.sendAdok()
  91. }, 1000)
  92. } else if (dataDict.status == 1) {
  93. //充值失败
  94. } else {
  95. //待审核中
  96. }
  97. } else if (eventType == "17WanShare") { //17分享
  98. } else if (eventType == "17WanAdReward") { //广告
  99. GameDataCenter.adVideo.onXiadanSucc() // 改成直接调用,不回调了
  100. } else if (eventType == "17WanAdLoad") { //广告加载完成
  101. console.log("17WanAdLoad adUnitId:", this.adId)
  102. if (!gameMethod.isEmpty(this.adId)) {
  103. NativeManager.CallToNative("On17ShowAd", [{ "Name": "sceneId", "Value": this.adId }], "")
  104. }
  105. }
  106. else if (eventType == "17WanChannel") { //获取渠道名称
  107. //GameDataCenter.plat.instance.channel = dataDict.channel
  108. }
  109. else if (eventType == "getClipboardText") {
  110. //EventMng.emit(duihuanEvent.GetText, dataDict.msg);
  111. }
  112. else {
  113. console.log("NativeNotify OnNativeNotify not find eventType: " + eventType);
  114. }
  115. }
  116. catch (error) {
  117. console.log("NativeNotify OnNativeNotify error: " + error.stack);
  118. }
  119. },
  120. }
  121. }
  122. showLoginView(): void {
  123. console.log("平台sdk初始化...")
  124. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.25, "login")
  125. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  126. NativeManager.CallToNative("On17WanInit", {}, "")
  127. }
  128. // 上报用户信息
  129. reportUserInfo(res) {
  130. console.log("上报用户信息", res)
  131. }
  132. // 上报角色数据
  133. reportRole(event: ReportRoleType): void {
  134. if (GameDataCenter.sevBack == null) { return }
  135. if (GameDataCenter.sevBack.userInfo == null) { return }
  136. console.log("上报角色数据:", event)
  137. let onlineTime = 0
  138. if (GameDataCenter.time.onlineTime > 0) {
  139. onlineTime = GameDataCenter.time.sevTime - GameDataCenter.time.onlineTime
  140. }
  141. let sceneValue = 0;
  142. if (event == ReportRoleType.create) {
  143. sceneValue = 1;
  144. } else if (event == ReportRoleType.levelup) {
  145. sceneValue = 2;
  146. }
  147. let power = GameDataCenter.zhanLi.getTotalZhanLi(GameDataCenter.sevBack);
  148. let clubName = GameDataCenter.sevBack?.club?.a?.name ?? "";
  149. let level = GameDataCenter.sevBack?.userInfo?.a?.level ?? 1;
  150. let sid = GameDataCenter.sevBack?.userInfo?.a?.sid;
  151. let itemNum = GameDataCenter.item.getItemCount(ConstItem.gem);
  152. let sex = GameDataCenter.sevBack.userInfo?.a?.sex;
  153. let exp = GameDataCenter.sevBack.actJingJie?.a?.exp;
  154. let iscz = GameDataCenter.sevBack.userInfo?.a?.iscz ?? 0;
  155. let regtime = GameDataCenter.sevBack.userInfo?.a?.regtime;
  156. let userInfo17 = {
  157. ingot: "",//游戏余额
  158. playerId: GameDataCenter.user.uuid,//角色ID
  159. factionName: clubName,//帮派
  160. vipLevel: "0",
  161. serverName: GameDataCenter.user.serverName,
  162. playerLevel: level,
  163. serverId: sid,
  164. playerName: GameDataCenter.user.nickName,
  165. campId: "",//阵营
  166. roleSex: sex,
  167. careerId: "",
  168. experience: exp,
  169. coin: itemNum,
  170. payment: iscz,
  171. roleCTime: regtime,
  172. sceneValue: sceneValue,
  173. }
  174. NativeManager.CallToNative("On17WanOutInGame", [{ "Name": "userInfo", "Value": JSON.stringify(userInfo17) }], "")
  175. }
  176. pay(orderId: string, order10cs: string, param: PayProductParam): void {
  177. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  178. let feePoint = order10cs;
  179. let payUrl: string = packageInfo.wayhttp + "player/pay/" + Config.pid
  180. NativeManager.CallToNative("On17WanPay", [{ "Name": "orderId", "Value": orderId }, { "Name": "url", "Value": payUrl }, { "Name": "sum", "Value": param.price.toString() }, { "Name": "feePoint", "Value": feePoint }, { "Name": "desc", "Value": param.productDesc }], "")
  181. //17玩 xiao7特殊处理,调支付就开始轮询,降低支付到账延迟
  182. // if (Config.paySuccAdokId != null) {
  183. // clearInterval(Config.paySuccAdokId)
  184. // Config.paySuccAdokId = null
  185. // }
  186. // Config.paySuccAdokIndex = 0
  187. // Config.paySuccAdokId = setInterval(() => {
  188. // Config.paySuccAdokIndex++
  189. // if (Config.paySuccAdokIndex >= 20) {
  190. // clearInterval(Config.paySuccAdokId)
  191. // Config.paySuccAdokId = null
  192. // }
  193. // GameDataCenter.time.sendAdok()
  194. // }, 1000)
  195. }
  196. initRewardedVideoAd(adkey: AD_VIDEO_KEY) {
  197. // GameDataCenter.plat.instance.adUnitId = GameDataCenter.adVideo.getAdUnitID(adkey)
  198. // NativeManager.CallToNative("On17LoadAd",[{"Name":"sceneId", "Value":GameDataCenter.plat.instance.adUnitId}],"")
  199. }
  200. showRewardAd(adId: string, kid: string, order11Id: string): void {
  201. this.adId = adId;
  202. NativeManager.CallToNative("On17ShowAd", [{ "Name": "sceneId", "Value": this.adId }], "")
  203. }
  204. //打开浏览器打开链接
  205. openUrl(url: string) {
  206. NativeManager.CallToNative("OnOpenBrowser", [{ "Name": "url", "Value": url }], "")
  207. }
  208. //看运营提供什么 提供手Q链接就用这个 , 提供网址链接就用浏览器打开
  209. addQQ(url: string) {
  210. NativeManager.CallToNative("OnAddQQ", [{ "Name": "url", "Value": url }], "")
  211. }
  212. joinQQGroup(url: string, cb?: Function) {
  213. NativeManager.CallToNative("OnJoinQQGroup", [{ "Name": "url", "Value": url }], "")
  214. if (cb) {
  215. cb();
  216. }
  217. }
  218. getChannel() {
  219. NativeManager.CallToNative("OnGetChannel", [], "")
  220. }
  221. share(title: string, imageUrl: string, query: string, contents?: string, hashtag_ids?: string, app_id?: string, group_label_id?: string): void {
  222. let data = {
  223. "title": title,
  224. "imageUrl": imageUrl,
  225. "query": query,
  226. "contents": contents,
  227. "hashtag_ids": hashtag_ids,
  228. "app_id": app_id,
  229. "group_label_id": group_label_id,
  230. }
  231. //NativeManager.CallToNative("OnShare2Tap",[{"Name":"data", "Value":JSON.stringify(data)}],"")//直接分享 (不存网图到本地)
  232. NativeManager.CallToNative("OnSaveUrlImg", [{ "Name": "data", "Value": JSON.stringify(data) }], "")// 存图并分享 (存图到本地再拉起分享)
  233. }
  234. getClipboardText(): void {
  235. NativeManager.CallToNative("getClipboardText", {}, "");
  236. }
  237. reShowLogInView(): void {
  238. NativeManager.CallToNative("On17WanLogin", {}, "");
  239. }
  240. }