test.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
  6. <title>Test</title>
  7. <link rel="stylesheet" href="__STATIC__/h5sdk/game/css/index.css">
  8. </head>
  9. <body>
  10. <div class="init">
  11. <div class="init_body">
  12. <a id="login" href="javascript:;" class="init_item">登录</a>
  13. <input type="text" id="amount" class="init_item" style="width: 100%; background-color: rgba(0, 0, 0, 0.5);"
  14. placeholder="请输入要充值的金额">
  15. <a id="pay" href="javascript:;" class="init_item">充值</a>
  16. <a id="uprole" href="javascript:;" class="init_item">发送角色信息</a>
  17. <a id="logout" href="javascript:;" class="init_item">退出登录</a>
  18. <a id="switch" href="javascript:;" class="init_item">切换账号</a>
  19. </div>
  20. </div>
  21. <script src="__STATIC__/h5sdk/js/huosdk.js?v={:config('js_version')}"></script>
  22. <script>
  23. if (/micromessenger/i.test(navigator.userAgent)) {
  24. $('#login, #switch').hide()
  25. }
  26. // 注册全局回调函数
  27. HuoSdk.callback = {
  28. init : function (res) {
  29. console.info('init callback', res)
  30. },
  31. login : function (res) {
  32. console.info('login callback', res)
  33. },
  34. pay : function (res) {
  35. console.info('pay callback', res)
  36. },
  37. uprole: function (res) {
  38. console.info('uprole callback', res)
  39. },
  40. logout: function (res) {
  41. console.info('logout callback', res)
  42. if (res.status === 2 && res.isSwitch) {
  43. HuoSdk.login()
  44. }
  45. }
  46. }
  47. // 初始化
  48. HuoSdk.init({
  49. app_id: '{$app_id}',
  50. mem_id: '{$mem_id}'
  51. })
  52. // 登录
  53. document.querySelector('#login').onclick = function () {
  54. HuoSdk.login()
  55. }
  56. // 支付
  57. document.querySelector('#pay').onclick = function () {
  58. HuoSdk.pay({
  59. 'order-order_id' : new Date().getTime(),
  60. 'order-currency' : 'CNY',
  61. 'order-cp_order_id' : 10000,
  62. 'order-product_price': $('#amount').val() || 1,
  63. 'order-product_id' : 1,
  64. 'order-product_name' : '金币',
  65. 'order-product_desc' : '',
  66. 'order-ext' : '123123',
  67. 'role-event' : 5,
  68. 'role-server_id' : '',
  69. 'role-server_name' : '',
  70. 'role-role_id' : '',
  71. 'role-role_name' : '',
  72. 'role-role_level' : 0,
  73. 'role-role_vip' : 0
  74. })
  75. }
  76. // 支付
  77. document.querySelector('#uprole').onclick = function () {
  78. HuoSdk.uprole({
  79. 'role-event' : 5,
  80. 'role-server_id' : random([1001, 1002, 2001, 2014, 3025]),
  81. 'role-server_name': random(['五谷丰登', '南蛮入侵', '万箭齐发', '无懈可击']),
  82. 'role-role_id' : random([20323, 31233, 30012, 10323]),
  83. 'role-role_name' : random(['张三', '李四', '王五']),
  84. 'role-role_level' : 0,
  85. 'role-role_vip' : 0,
  86. 'role-onlineTime' : 0,
  87. 'role-scene' : '',
  88. 'role-axis' : ''
  89. })
  90. }
  91. // 登出
  92. document.querySelector('#logout').onclick = function () {
  93. HuoSdk.logout()
  94. }
  95. // 切换
  96. document.querySelector('#switch').onclick = function () {
  97. HuoSdk.logout(true)
  98. }
  99. // 随机值
  100. function random(arr) {
  101. var r = Math.floor(Math.random() * arr.length)
  102. return arr[r]
  103. }
  104. </script>
  105. </body>
  106. </html>