适配 wx mini game

This commit is contained in:
MiaoRunZhuang 2024-06-26 11:25:59 +08:00
parent b81e03e19b
commit 978ac5242b
10 changed files with 260 additions and 116 deletions

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -8,37 +8,53 @@ export enum TrackingType {
/** 三倍积分 */
TriplePickup = 'triple-pickup',
/** 恢复 */
Recover= 'recover',
Recover = 'recover',
/** 免费试用 */
FreeTrial= 'free-trial',
FreeTrial = 'free-trial',
}
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}
if (!CC_EDITOR) {

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -13,28 +13,44 @@ export enum TrackingType {
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}

View File

@ -12,7 +12,7 @@
"webOrientation": "portrait",
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"mainCompressionType": "default",
"mainCompressionType": "merge_all_json",
"mainIsRemote": false,
"optimizeHotUpdate": false,
"md5Cache": true,

View File

@ -29,7 +29,7 @@
"width": 960,
"height": 640
},
"last-module-event-record-time": 1713875646410,
"last-module-event-record-time": 1719369333686,
"assets-sort-type": "name",
"facebook": {
"enable": false,

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -19,28 +19,44 @@ export enum TrackingType {
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}

View File

@ -0,0 +1,23 @@
{
"name": "ChaoJiJieYaGuan_MaJiang2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@types/bcryptjs": "^2.4.6",
"bcryptjs": "^2.4.3"
}
},
"node_modules/@types/bcryptjs": {
"version": "2.4.6",
"resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.6.tgz",
"integrity": "sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ=="
},
"node_modules/bcryptjs": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
"integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ=="
}
}
}

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, getSalt, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -15,30 +15,46 @@ export enum TrackingType {
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}
if (!CC_EDITOR) {

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -13,30 +13,46 @@ export enum TrackingType {
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}
if (!CC_EDITOR) {

View File

@ -1,4 +1,4 @@
import {genSaltSync, hashSync} from 'bcryptjs';
import {genSaltSync, hashSync, setRandomFallback} from 'bcryptjs';
export enum TrackingType {
/** 进入游戏 */
@ -13,30 +13,46 @@ export enum TrackingType {
const KEY = `sssssssssk`;
try {
genSaltSync(10);
} catch (e) {
setRandomFallback(function (bytes) {
const randomBytes = new Array(bytes);
for (var i = 0; i < bytes; i++) {
randomBytes[i] = Math.floor(Math.random() * 256);
}
return randomBytes;
});
}
export class TrackingManager {
public static async send(type: TrackingType) {
public static send(type: TrackingType) {
const salt = genSaltSync(10);
const hash = hashSync(KEY, salt);
const formData = new FormData();
formData.append('listener', type);
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
method: "POST",
headers: {
Key: hash,
Href: location.href
},
body: formData
});
var xhr = new XMLHttpRequest();
xhr.open("POST", 'https://api.ad.game.06zk.com/app/anchor');
const data = await res.json();
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Key", hash);
xhr.setRequestHeader("Href", location.href);
const formData = `listener=${type}`;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
const data = JSON.parse(xhr.responseText);
if (data.code === 200) {
console.log(`上报${type}成功`);
} else {
console.log(`上报${type}失败`);
}
}
};
xhr.send(formData);
}
}
if (!CC_EDITOR) {

View File

@ -5,7 +5,8 @@
"pathPattern": "",
"recordPath": "",
"scheme": "https",
"skipRecord": false
"skipRecord": false,
"packageName": "org.cocos2d.demo"
},
"appBundle": false,
"baidugame": {
@ -20,7 +21,7 @@
"includeSDKBox": false,
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"md5Cache": false,
"md5Cache": true,
"mergeStartScene": false,
"optimizeHotUpdate": false,
"orientation": {
@ -46,5 +47,29 @@
"subContext": "open"
},
"xxteaKey": "a9d0135f-0d6f-4f",
"zipCompressJs": true
"zipCompressJs": true,
"mainCompressionType": "default",
"mainIsRemote": false,
"nativeMd5Cache": true,
"android": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": ""
},
"ios": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": "",
"ios_enable_jit": true
},
"mac": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": "",
"width": 1280,
"height": 720
},
"win32": {
"REMOTE_SERVER_ROOT": "",
"width": 1280,
"height": 720
},
"agreements": {}
}