test.html 3.5 KB

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