填写appid 和游戏资源位置
在导出的项目里可以修改游戏资源位置 两个目录 minigame 是小程序打开的目录 webgl 是要下载的的资源 下载一个http 服务器就有了
和JS交互 大部分js 功能都被封装到了C# 只用做少量的即可
在wx-wasm-sdk 下得 Plugins 目录下新建文件 Channel.jslib
mergeInto(LibraryManager.library, {
WebChannelLogin: function () {
window.WXWASMSDK.WebChannelLogin();
},
WebTrackEvent: function(platName,eventName){
window.WXWASMSDK.WebTrackEvent(_WXPointer_stringify_adaptor(platName),_WXPointer_stringify_adaptor(eventName));
},
WebPayItem: function(arg){
window.WXWASMSDK.WebPayItem(_WXPointer_stringify_adaptor(arg));
},
WebCallChannelVoidFunWithArg: function(name, arg) {
window.WXWASMSDK.WebCallChannelVoidFunWithArg(_WXPointer_stringify_adaptor(name),_WXPointer_stringify_adaptor(arg));
},
WebSetUserData: function(arg){
window.WXWASMSDK.WebSetUserData(_WXPointer_stringify_adaptor(arg));
},
WebTanWanEvent: function(name, arg){
window.WXWASMSDK.WebTanWanEvent(_WXPointer_stringify_adaptor(name),_WXPointer_stringify_adaptor(arg));
},
});
他其实和Lua 的全表有点像
新建 apps文件
import { appEntity } from './app-entity';
import * as appSystem from './app-system'
var ThinkingAnalyticsAPI = require("./thinkingdata.mg.wx.min.js");
//import sdk from "./oreyunwx.min.js"
import {
init,
loginUserInfo,
dataReport,
makePayment,
shareAppMessage,
payConfig,
navigateToMiniProgram,
getBindPhoneCode,
bindPhone,
onShareAppMessage,
requestSubscribeMessage,
triggerSubscribe,
createAd
} from 'gameSDK.bundle.js'
var ta;
export default {
WebChannelLogin(){
//获取微信品台
wx.getSystemInfo({
success (res) {
if(res.platform === "ios"){
payConfig().then(res => {
let iosPay = "1"
if(res.ios_recharge === true && obj.RoleLv > res.ios_level){
iosPay = "1"
}
else{
iosPay = "0"
}
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverIosPayConfig",iosPay);
console.log("ios pay " + JSON.stringify(res))
}).catch(error => {
console.log("ios pay " + error)
})
}
}
})
if(appEntity.account\_id !== ""){
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverChannelLoginCallBack",appEntity.account\_id);
var presetProperties = appEntity.ta.getPresetProperties();
var properties = presetProperties.toEventPresetProperties();
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverPresetProperties",JSON.stringify(properties));
console.log("properties " + JSON.stringify(properties))
return
}
loginUserInfo().then(res => {
console.log("loginUserInfo " + res.uid)
appEntity.account\_id = res.uid + ""
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverChannelLoginCallBack",appEntity.account\_id);
var presetProperties = appEntity.ta.getPresetProperties();
var properties = presetProperties.toEventPresetProperties();
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverPresetProperties",JSON.stringify(properties));
ta.login(appEntity.account\_id)
}).catch(error => {
})
},
WebTrackEvent(eventName,arg){
//console.log(eventName);
//console.log(arg);
if (arg.length > 0) {
var obj = JSON.parse(arg);
ta.track(eventName,obj)
}
else{
ta.track(eventName,{})
}
},
WebPayItem(arg){
//console.log("sha1", appSystem.sha1("1646989046234D528C6F23C7D7"))
var obj = JSON.parse(arg)
if(obj.wx\_android === false){
payConfig().then(res => {
if(res.ios\_recharge === true && obj.RoleLv > res.ios\_level){
UpPay(obj)
}
else{
let objd = {
code:1,
info:"iOS 用户等级不够"
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
}
console.log("ios pay " + JSON.stringify(res))
}).catch(error => {
})
}
else{
UpPay(obj)
}
},
WebSetUserData(arg){
var obj = JSON.parse(arg)
ta.userSet(obj);
},
WebCallChannelVoidFunWithArg(name,arg){
//GameGlobal.Module.SendMessage("Canvas","ChannelLogout","hahhahah")
//appSystem.exportTest1()
//appSystem.exportTest2("zhang san")
//appSystem.csharp(1,"sss");
//ta.login("ABC\_123456");
if(name === "setSuperProperties"){
var obj = JSON.parse(arg)
ta.setSuperProperties(obj);
}
else if(name === "userSet"){
var obj = JSON.parse(arg)
ta.userSet(obj);
}
else if(name === "unityHasInit"){
appEntity.unityHasInit = true
}
else if(name === "actionRegister"){
ReyunRegister()
appSystem.PostSourceRegister()
}
else if(name === "actionLogin"){
ReyunLogin()
}
else if(name === "actionPurchase"){
var obj = JSON.parse(arg)
ReyunPayment(obj);
//appSystem.PostSourcePay(obj.currencyAmount \* 100)
}
else if(name === "showRewardedVideo"){
createAd({
ad\_type:"video",
task:''
}).then(res => {
adHandler("onRewardedVideoAdRewarded","")
adHandler("onRewardedVideoAdClosed","")
//GameGlobal.Module.SendMessage(appEntity.receivername,"onRewardedVideoAdRewarded","");
//GameGlobal.Module.SendMessage(appEntity.receivername,"onRewardedVideoAdClosed","");
console.log("showRewardedVideo222 " + JSON.stringify(res))
}).catch(error => {
console.log("showRewardedVideo11111 " + JSON.stringify(error))
})
console.log("VoidFunWithArg " + name + "---" + arg);
}
else if(name === "SDKInit"){
let tanwandata = {
app\_version: arg,
config\_id: '',
game\_name: ''
};
// 初始化小游戏SDK
init(tanwandata).then(res => {
wx.showToast({
title: '进入游戏成功',
})
//拉起订阅
requestSubscribeMessage()
//触发订阅
triggerSubscribe('login')
}).catch(error => {
})
let org = {
userType:"TanWan"
}
ta.userSet(org);
console.log("VoidFunWithArg " + name + "---" + arg);
}
},
WxInit(){
//u8参数初始化
//appSystem.InitU8Arg();
//数数初始化
ShushuInit();
//热云初始化
///sdk.init(appEntity.reYunAppKey);
//登录
//appSystem.channelLogin();
//归因初始化
//SourceInit()
},
WebTanWanEvent(eventName,arg){
var obj = JSON.parse(arg)
let reportArg = {}
if(eventName === "1"){
reportArg.data\_type = 1
}
else if(eventName === "2"){
reportArg.data\_type = 2
}
else if(eventName === "3"){
reportArg.data\_type = 3
}
else if(eventName === "4"){
reportArg.data\_type = 4
}
reportArg.server\_id = 1
reportArg.server\_name = ""
reportArg.uid = obj.RoleId
reportArg.role\_id = obj.RoleId
reportArg.role\_name = ""
reportArg.role\_level = obj.RoleLv
reportArg.role\_currency = obj.MoneyNum
reportArg.role\_create\_time = obj.RoleCreateTime
reportArg.fight = 1
reportArg.role\_sex = 1
reportArg.vip\_level = 1
reportArg.role\_career = ""
dataReport(reportArg).then(res => {
}).catch(error => {
})
console.log("WebTanWanEvent " + JSON.stringify(reportArg))
},
GetOpenId(openid) {
//console.log("account\_id " + openid)
ta.login(appEntity.account\_id);
},
ShushuEventTimeStart(eventName){
ta.timeEvent(eventName);
},
ShushuJsTrack(eventName,obj){
ta.track(eventName,obj)
}
}
function SendPayResultMessage(re){
console.log("SendPayResult",re)
GameGlobal.Module.SendMessage(appEntity.receivername,"PayResult",re);
}
function ShushuInit(wxcode){
var config = {
appId:appEntity.shushuAppId, // 项目 APP ID
serverUrl:appEntity.shushuUrl , // 上报地址
enableLog:false,
autoTrack: {
appShow: true, // 自动采集 ta_mg_show
appHide: true // 自动采集 ta_mg_hide
}
};
// 创建 TA 实例
ta = new ThinkingAnalyticsAPI(config);
// 初始化
ta.init();
ta.identify(ta.getDeviceId());
appEntity.ta = ta;
//console.log("shushu init")
//console.log("getDeviceId",ta.getDeviceId());
// 上报一个简单事件, 事件名为 test_event
}
function UpPay(obj){
var payArg = {}
payArg.uid = "1"
payArg.server_id = "1"
payArg.server_name = "正式服"
payArg.role_id = "1"
payArg.role_name = "1"
payArg.role_level = 1
payArg.role_currency = 1
payArg.amt = obj.Fee / 100
payArg.game_fee = 1
payArg.product_id = obj.detail
payArg.product_name = "游戏充值"
payArg.product_desc = "游戏充值"
payArg.ext = obj.gameOrderId + ",1174" + "," + obj.rig
console.log("payArg" + JSON.stringify(payArg))
makePayment(payArg).then(payres => {
wx.getSystemInfo({
success (res) {
if(res.platform === "ios"){
}
else{
let objd = {
code:0,
info:"轮询"
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
}
}
})
}).catch(error => {
})
}
//热云注册接口
function ReyunRegister(){
//sdk.register(appEntity.wxopenId)
}
function ReyunLogin(){
//sdk.loggedin(appEntity.account_id)
}
function ReyunPayment(arg){
//js["transactionId"] = transactionId;
//js["currencyAmount"] = currencyAmount;
//js["currencyType"] = currencyType;
//js["paymentType"] = paymentType;
//sdk.payment(arg.transactionid,arg.currencyamount,arg.currencytype,arg.paymenttype)
}
function SourceInit() {
let jsobj = wx.getStorageSync('Source')
var bb = Object.keys(jsobj)
if(bb.length === 0){
//if(true){
//debugger
let objs = wx.getLaunchOptionsSync()
if ('query' in objs) {
let qurayStr = JSON.stringify(objs.query)
if (qurayStr.length > 0) {
ta.userSet(qurayStr)
}
}
if ('query' in objs) {
if ('clue\_token' in objs.query) {
appEntity.clue\_token = objs.query.clue\_token;
}
if ('ad\_id' in objs.query) {
appEntity.ad\_id = objs.query.ad\_id;
}
if ('creative\_id' in objs.query) {
appEntity.creative\_id = objs.query.creative\_id;
}
if ('req\_id' in objs.query){
appEntity.req\_id = objs.query.req\_id;
}
if ('advertiser\_id' in objs.query) {
appEntity.advertiser\_id = objs.query.advertiser\_id;
}
if ('project\_id' in objs.query) {
appEntity.advertiser\_id = objs.query.project\_id;
}
if ('promotion\_id' in objs.query) {
appEntity.advertiser\_id = objs.query.promotion\_id;
}
if ('mid1' in objs.query) {
appEntity.mid1 = objs.query.mid1;
}
if ('mid2' in objs.query) {
appEntity.mid2 = objs.query.mid2;
}
if ('mid3' in objs.query) {
appEntity.mid3 = objs.query.mid3;
}
if ('mid4' in objs.query) {
appEntity.mid4 = objs.query.mid4;
}
if ('mid5' in objs.query) {
appEntity.mid5 = objs.query.mid5;
}
}
let obj = {
ad\_id:appEntity.ad\_id,
creative\_id:appEntity.creative\_id,
advertiser\_id:appEntity.advertiser\_id,
clue\_token:appEntity.clue\_token,
};
let str = JSON.stringify(obj);
//console.log(str);
wx.setStorageSync('Source',str)
appEntity.firstOpen = true;
}
else{
let sorObj = JSON.parse(jsobj);
appEntity.ad\_id = sorObj.ad\_id;
appEntity.creative\_id = sorObj.creative\_id;
appEntity.advertiser\_id = sorObj.advertiser\_id;
appEntity.clue\_token = sorObj.clue\_token;
}
}
function adHandler(funName,arg){
let obj = {
"FunName":funName,
"Arg":arg
}
let tarStr = JSON.stringify(obj)
console.log("tarStr " + tarStr)
GameGlobal.Module.SendMessage(appEntity.receivername,"AdHandler",tarStr);
}
在index 中将 apps 方法注册到全局表中
import apps from './apps';
const WXWASMSDK = {
/*
初始化
*/
WXInitializeSDK() {
moduleHelper.init();
moduleHelper.send('Inited', 200);
},
…storage,
…userInfo,
…share,
…ad,
…canvasHelper,
…fs,
…openData,
…util,
…cloud,
…audio,
…texture,
…video,
…logger,
…shortAudio,
…gameClub,
canvasContext,
…sdk,
…camera,
…recorder,
…uploadFile,
…gameRecorder,
…apps, //加的这个
};
SDK 初始化在 Game.js 中
GameGlobal.WXWASMSDK.WxInit();
实为apps 的调用方法
新建 app-system
import {appEntity} from './app-entity';
import {appSanboxCfg} from './appSanboxCfg';
import { CryptoJS } from './CryptoJS.js';
export function exportTest1() {
}
export function exportTest2(name) {
}
export function csharp(id,errMsg){
}
export function js(){
}
export function u8Post(url, postData, doSuccess, doFail){
var base = appEntity.u8ServerUrl
wx.request({
//项目的真正接口,通过字符串拼接方式实现
url: base + url,
// 这个header根据你的实际改!
header:{
'X-GameId':appEntity.u8GameId,
'X-ChannelId':appEntity.u8ChannelId,
'X-PackageId':appEntity.u8PackageId,
'Content-Type': 'application/json',
'cookie': appEntity.u8HttpToken,
'Request-Origin': 'app'
},
data: postData,
method: 'POST',
success: function (res) {
//参数值为res.data,直接将返回的数据传入
//if (res.data.result.token) { // 如果有token保存下来,下次请求带着token访问
// appEntity.u8HttpToken = res.data.result.token;
// console.log("token--> ", appEntity.u8HttpToken)
//}
doSuccess(res.data);
},
fail: function () {
doFail();
},
})
}
export function u8GetData(url, getData, doSuccess, doFail) {
wx.request({
url: url,
header: {
'Content-Type': 'application/json',
'X-Access-Token': appEntity.u8HttpToken,
'Request-Origin': 'app'
},
method: 'GET',
data: getData,
success: function (res) {
doSuccess(res.data);
},
fail: function () {
doFail();
},
})
}
export function getSignStringFromObj(obj){
let arrIndex = 0;
let arr = [];
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
arr[arrIndex] = {
paramKey:key,
paramVal:obj[key],
}
arrIndex = arrIndex + 1
}
}
arr.sort(compare);
let targeStr = "";
for(var i = 0; i < arr.length; i++){
if(targeStr !== ""){
targeStr = targeStr + "&"
}
targeStr = targeStr + arr[i].paramKey + "=" + arr[i].paramVal;
}
obj.timestamp = Date.now();
obj.nonce = 3652;
targeStr = targeStr + "&" + "timestamp="+ obj.timestamp +"&nonce=" + obj.nonce
//console.log("test target " + targeStr);
return targeStr;
}
export function channelLogin(){
//u8 完成登录就不回去登录
if(appEntity.account_id !== ""){
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverChannelLoginCallBack",appEntity.account_id);
var presetProperties = appEntity.ta.getPresetProperties();
var properties = presetProperties.toEventPresetProperties();
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverPresetProperties",JSON.stringify(properties));
console.log("properties " + JSON.stringify(properties))
return
}
wx.login({
success: function(res) {
//console.log(res.code);//这里的返回值就有Code信息
u8Login(res.code);
//debugger;
},
fail: function(res) {
let loginArg = {
result:false,
fail_reason:"wx fail",
}
GameGlobal.WXWASMSDK.ShushuJsTrack("U8_init",loginArg);
},
complete: function(res) {},
})
}
function u8Login(code){
let url = "usercenter/wx1/login";
let data = {
wx_code : code,
}
let signCode = getSignStringFromObj(data);
var hash_result = CryptoJS.HmacSHA256(signCode, appEntity.u8Sign).toString();
data.sign = hash_result;
u8Post(url,data,
function(succ){
if(succ.code === 200){
appEntity.account_id = succ.data.account_id;
appEntity.wxopenId = succ.data.openid;
//console.log("wxopenId " + succ.data.openid)
//debugger
appEntity.wxtoken = succ.data.token;
//热云初始化,数数login
GameGlobal.WXWASMSDK.GetOpenId(appEntity.wxopenId);
//这个要微信的数据
PostSourceActive()
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverChannelLoginCallBack",appEntity.account_id);
var presetProperties = appEntity.ta.getPresetProperties();
//生成事件预置属性
var properties = presetProperties.toEventPresetProperties();
GameGlobal.Module.SendMessage(appEntity.receivername,"ReceiverPresetProperties",JSON.stringify(properties));
let loginArg = {
result:true,
fail_reason:"u8 server ok",
}
GameGlobal.WXWASMSDK.ShushuJsTrack("U8_init",loginArg);
let reArg = {
login\_type:"weixin",
login\_id:appEntity.account\_id,
result:true,
fail\_reason:"ok"
}
GameGlobal.WXWASMSDK.ShushuJsTrack("login\_result",reArg);
}
else{
let loginArg = {
result:false,
fail\_reason:succ.message,
}
GameGlobal.WXWASMSDK.ShushuJsTrack("U8\_init",loginArg);
}
},
function(){
let loginArg = {
result:false,
fail\_reason:"u8 server error",
}
GameGlobal.WXWASMSDK.ShushuJsTrack("U8\_init",loginArg);
})
}
function compare(obj1, obj2) {
let val1 = obj1.paramKey;
let val2 = obj2.paramKey;
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
//用户点击了支付
export function wxPay(csobj){
wx.login({
success: function(res) {
upWxPay(csobj,res.code)
},
fail: function(res) {
let objd = {
code:1,
info:"获取微信code失败"
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
},
complete: function(res) {
},
})
}
function getSignature(arg,succfunc) {
let data = {
account_id:appEntity.account_id,
nickname:arg.nickName,
gender:arg.gender,
language:arg.language,
city:arg.city,
province:arg.province,
country:arg.country,
avatar_url:arg.avatarUrl,
}
let signCode = getSignStringFromObj(data);
var hash_result = CryptoJS.HmacSHA256(signCode, appEntity.u8Sign).toString();
data.sign = hash_result;
//debugger
u8Post("/usercenter/wx1/min/signature",data,
function(params) {
appEntity.signature = params.data.signature;
succfunc(params)
//debugger
},
function(params) {
})
}
function upWxPay(csobj,wxcode) {
let arg = {
mode:"game",
env:appEntity.env,
offerId:appEntity.offerId,
currencyType:"CNY",
platform:"android",
buyQuantity:csobj.Fee / 10,
zoneId:"1",
success:function(res){
//console.log("paysucc " + JSON.stringify(res))
webAndroidMoneyHasGone(csobj,wxcode)
},
fail:function(res){
//console.log(res)
let objd = {
code:1,
info:res
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
webAndroidMoneyHasGone(csobj,wxcode)
console.log("payfail " + JSON.stringify(res))
},
complete:function(){
//通知服务器去微信服扣货
},
};
//拉起微信支付
wx.requestMidasPayment(arg);
//webAndroidMoneyHasGone(csobj,wxcode)
//console.log("appEntity.offerId offerIdofferId " + appEntity.offerId)
}
function webAndroidMoneyHasGone(objCharp,code){
let postData = {};
postData.env = appEntity.env
postData.openid = appEntity.wxopenId;
//postData.appid = appEntity.wxAppId;
postData.offer_id = appEntity.offerId;
postData.zone_id = 1
postData.access_token = appEntity.weixinServerToken;
postData.game_orderid = objCharp.gameOrderId
postData.js_code = code
postData.accountid = appEntity.account_id
//debugger
var base = appEntity.webAndroidPayUrl;
//console.log("base" + base)
wx.request({
//项目的真正接口,通过字符串拼接方式实现
url: base,
// 这个header根据你的实际改!
header: {
'Content-Type': 'application/json',
'Request-Origin': 'app'
},
data: postData,
method: 'POST',
success: function (res) {
//debugger
let objd = {
code:0,
info:"支付成功"
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
},
fail: function () {
//debugger
//doFail();
let objd = {
code:1,
info:"从微信扣款失败"
}
let jsString = JSON.stringify(objd);
SendPayResultMessage(jsString)
},
})
}
function encodeUTF8(s) {
var i, r = [], c, x;
for (i = 0; i < s.length; i++)
if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
else {
if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
else r.push(0xE0 + (c >> 12 & 0xF));
r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
};
return r;
};
// 字符串加密成 hex 字符串
export function sha1(s) {
var data = new Uint8Array(encodeUTF8(s))
var i, j, t;
var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2);
s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
for (t = new DataView(s.buffer), i = 0; i < l; i++)s[i] = t.getUint32(i << 2);
s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
s[l - 1] = data.length << 3;
var w = [], f = [
function () { return m[1] & m[2] | ~m[1] & m[3]; },
function () { return m[1] ^ m[2] ^ m[3]; },
function () { return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; },
function () { return m[1] ^ m[2] ^ m[3]; }
], rol = function (n, c) { return n << c | n >>> (32 - c); },
k = [1518500249, 1859775393, -1894007588, -899497514],
m = [1732584193, -271733879, null, null, -1009589776];
m[2] = ~m[0], m[3] = ~m[1];
for (i = 0; i < s.length; i += 16) {
var o = m.slice(0);
for (j = 0; j < 80; j++)
w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
for (j = 0; j < 5; j++)m[j] = m[j] + o[j] | 0;
};
t = new DataView(new Uint32Array(m).buffer);
for (var i = 0; i < 5; i++)m[i] = t.getUint32(i << 2);
var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
return (e < 16 ? "0" : "") + e.toString(16);
}).join("");
return hex;
};
function PostSourceActive() {
if (appEntity.firstOpen) {
let jsondata = {
clue_token:appEntity.clue_token,
open_id:appEntity.wxopenId,
event_type:"0"
}
PostSourceHttp(jsondata)
}
}
export function PostSourceRegister() {
let jsondata = {
clue_token:appEntity.clue_token,
open_id:appEntity.wxopenId,
event_type:"1"
}
PostSourceHttp(jsondata)
}
export function PostSourcePay(amount) {
let jsondata = {
clue_token:appEntity.clue_token,
open_id:appEntity.wxopenId,
event_type:"2",
props:{
pay_amount:amount
}
}
PostSourceHttp(jsondata)
}
function PostSourceHttp(jsondata){
let time = Date.now();
let nonce = Math.round(Math.random()*10);
let strList = [appEntity.sourcetoken, time, nonce];
strList.sort();
let buffer = "";
strList.forEach(str => {
buffer += str;
})
let sign = sha1(buffer)
//debugger
let targeturl = appEntity.sourceUrl + "?timestamp=" + time + "&nonce="+ nonce +"&signature=" + sign
//console.log("url " + targeturl)
wx.request({
url:targeturl,
header: {
'Content-Type': 'application/json',
'Request-Origin': 'app'
},
data: jsondata,
method: 'POST',
success: function (res) {
//console.log("zhangsan " + JSON.stringify(res.data))
},
fail:function(){
},
})
}
export function WebiOSPay(obj){
let amount = obj.Fee;
let accid = appEntity.account_id;
let url = appEntity.webiOSNotPayUrl;
let extension = obj.extension
let server_id = 1
let game = obj.body
let goods = "方块大作战充值"
let targetStr = `../index/index?notify_type=createorder&amount=${amount}&account_id=${accid}¬ify_url=${url}&extension=${extension}&server_id=${server_id}&game=${game}&goods=${goods}`
//console.log(targetStr + "targetStr")
wx.openCustomerServiceConversation({
showMessageCard: true,
sessionFrom: "game",
sendMessagePath:targetStr,
sendMessageTitle:"我要充值",
sendMessageImg: "https://c-ssl.duitang.com/uploads/blog/202102/12/20210212163554_83b7a.jpg",
success() {
//console.log('调起成功');
},
fail() {
//console.log('调起失败');
}
});
}
export function SendPayResultMessage(re){
//console.log("zhangsan",re)
GameGlobal.Module.SendMessage(appEntity.receivername,"PayResult",re);
}
export function InitU8Arg() {
if (appSanboxCfg.sanbox) {
appEntity.u8appid = appEntity.u8
appEntity.u8GameId = appEntity.u8GameIdTest;
appEntity.u8ChannelId = appEntity.u8ChannelIdTest;
appEntity.u8PackageId = appEntity.u8PackageIdTest;
appEntity.u8Sign = appEntity.u8SignTest;
appEntity.u8ServerUrl = appEntity.u8ServerUrlTest;
appEntity.env = appEntity.envTest
}
}
还有个app-entity 存放变量的
export var appEntity = {
//与U8交互的口令 暂时没有用
u8HttpToken : null,
//测试参数
u8appidTest:,
u8GameIdTest : "",
u8ChannelIdTest : "",
u8PackageIdTest : "",
u8SignTest:"",
u8ServerUrlTest:"",
//正式参数
u8appid:,
u8GameId : "",
u8ChannelId : "",
u8PackageId : "",
u8Sign:"",
u8ServerUrl:"",
//登录获取的账户id
account_id:"",
//微信的union_id
union_id:'',
//登录获取的微信id
wxopenId:"",
//后端与微信后端交互口令
wxtoken:"",
//unity 是否初始胡完成
unityHasInit:false,
//webAndroid 支付url
webAndroidPayUrl:"",
//微信后台虚拟货币id
//offerId:"",
offerId:"",
//微信的appid
wxAppId:"",
env:0,
envTest:1,
//热云appkey
reYunAppKey:"",
//
receivername:"Global",
//游戏服和微信服交互的token
weixinServerToken:"",
//归因
ad\_id:'',
creative\_id:'',
advertiser\_id:'',
clue\_token:'',
req\_id:'',
project\_id:'',
promotion\_id:'',
mid1:'',
mid2:'',
mid3:'',
mid4:'',
mid5:'',
firstOpen:false,
// 归因服url
sourceUrl:"",
sourcetoken:"",
webiOSNotPayUrl:"",
//数数
shushuAppId:"",
shushuUrl:"",
ta:"",
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章