sdk.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. export default class boxSdk {
  2. constructor(name) {
  3. // this.cache = wx.getStorageSync('sdkStorage')
  4. this.heziUrl = '',
  5. this.name = name,
  6. this.api = 'https://www.27l.com/'
  7. this.img = null
  8. }
  9. showAdIcon(x, y, node) {
  10. let self = this
  11. // var img = wx.createImage()
  12. // if (self.cache && self.cache.ad_icon) {
  13. // img.src = self.cache.ad_icon.small_icon
  14. // img.onload = function() {
  15. // self.renderIcon(x, y, canvas, img)
  16. // }
  17. // }
  18. wx.request({
  19. url: `${self.api}hz/common`,
  20. data: {},
  21. success: function ({ data }) {
  22. console.log(data)
  23. self.heziUrl = data.data.hz_picture
  24. //获取图片进一步操作
  25. let icon = data.data.ad_icon.small_icon.replace(/http\:\/\//,'https://')
  26. // img.src = icon
  27. self.renderIcon(x, y, icon, node)
  28. }
  29. })
  30. }
  31. renderIcon(x, y, texture, parent) {
  32. var self = this
  33. var img = wx.createImage()
  34. img.src = texture
  35. self.img = img
  36. wx.downloadFile({
  37. url: texture,
  38. header: {},
  39. filePath: '',
  40. success: function (ret) {
  41. console.log(ret)
  42. var frame = new cc.SpriteFrame(ret.tempFilePath);
  43. // self.node.getComponent('adIcon').spriteFrame=frame;
  44. var node = new cc.Node('adIcon');
  45. var sp = node.addComponent(cc.Sprite);
  46. var widget = node.addComponent(cc.Widget)
  47. var btn = node.addComponent(cc.Button)
  48. btn.node.on(cc.Node.EventType.TOUCH_START, function () {
  49. wx.previewImage({
  50. urls: [self.heziUrl]
  51. })
  52. wx.request({
  53. url: `${self.api}hz/static?field=img`,
  54. data: { name: self.name },
  55. success: () => { }
  56. })
  57. })
  58. widget.isAlignTop = true
  59. widget.isAlignLeft = true
  60. widget.left = x
  61. widget.top = y
  62. sp.spriteFrame = frame
  63. node.parent = parent;
  64. console.log(widget)
  65. console.log(sp)
  66. }
  67. })
  68. }
  69. openQrcode() {
  70. let self = this
  71. wx.request({
  72. url: `${self.api}hz/common`,
  73. data: {},
  74. success: ({ data }) => {
  75. wx.previewImage({
  76. urls: [data.data.gzh_qr_code]
  77. })
  78. }
  79. })
  80. }
  81. oepnGameCenter() {
  82. wx.request({
  83. url: `${self.api}hz/common`,
  84. data: {},
  85. success: ({ data }) => {
  86. wx.previewImage({
  87. urls: [data.data.hz_picture]
  88. })
  89. }
  90. })
  91. }
  92. initSdk(sceneId, path) {
  93. let gameName = this.name
  94. if (sceneId == 1012) {
  95. wx.request({
  96. url: `${self.api}hz/static?field=qr`,
  97. data: { name: gameName },
  98. success: () => { },
  99. })
  100. }
  101. }
  102. }