CocosCreator 小游戲H5主流渠道聚合SDK

源碼地址見:https://github.com/RainUnity/GameSDK/blob/main/description/SDK.js

或直接參考下方

/**

* description:H5小游戲主流渠道聚合SDK(微信,手Q,支付寶,OPPO,VIVO,HUAWEI,BAIDU,XIAOMI等渠道的登錄及支付調(diào)用接口),持續(xù)開發(fā)中。。。。。。

* author: 白

* date: 2020.4.18

* version:1.0.0

* compiler environment: Cocos Creator v2.3.1.0

*/

cc.Class({

? ? extends: cc.Component,

? ? properties: {

? ? ? ? loginBtn: cc.Button,

? ? ? ? payBtn: cc.Button,

? ? ? ? Info: cc.Label,

? ? },

? ? onLoad() {

? ? ? ? this.loginBtn.node.on('click', this.login, this);

? ? ? ? this.payBtn.node.on('click', this.pay, this);

? ? },

? ? login: function (event) {

? ? ? ? this.ctoaslogin();

? ? ? ? //this.Info.string ="登錄";

? ? ? ? //this.wxLogin();

? ? ? ? // this.qqLogin();

? ? ? ? // this.aliLogin();

? ? ? ? // this.oppoLogin();

? ? ? ? // this.vivoLogin();

? ? ? ? // this.huaweiLogin(true);

? ? ? ? //this.baiduLogin();

? ? ? ? //this.xioamiLogin();

? ? },

? ? /**

? ? *

? ? *調(diào)用支付

? ? */

? ? pay: function (event) {

? ? ? ? console.log("點(diǎn)擊了支付按鈕");

? ? ? ? //this.wxPay();

? ? ? ? // this.qqPay();

? ? ? ? // this.aliPay();

? ? ? ? // this.oppoPay();

? ? ? ? // this.vivoPay();

? ? ? ? // this.huaweiPay();

? ? ? ? // this.baiduPay();

? ? ? ? //this.xioamiPay();

? ? },

? ? ctoaslogin()

? ? {

? ? ? console.log("點(diǎn)擊了登錄按鈕")

? ? ? var obj =? jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Test", "login","(I)Ljava/lang/String;", 6);

? ? ? this.Info.string =obj;

? ? },

? ? /**

? ? * 微信登錄? 官方文檔見https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html

? ? */

? ? wxLogin() {

? ? ? ? // let exportJson = {};

? ? ? ? // let sysInfo = wx.getSystemInfoSync();

? ? ? ? // //獲取微信界面大小

? ? ? ? // let width = sysInfo.screenWidth;

? ? ? ? // let height = sysInfo.screenHeight;

? ? ? ? // wx.login({

? ? ? ? //? ? success: (res) => {

? ? ? ? //? ? ? ? if (res.code) {

? ? ? ? //? ? ? ? ? ? console.log("獲取到的code:", res.code);

? ? ? ? //? ? ? ? ? ? exportJson.code = res.code;//向服務(wù)端傳遞code用于獲取微信小游戲的用戶唯一標(biāo)識(shí)

? ? ? ? //? ? ? ? ? ? //發(fā)起網(wǎng)絡(luò)請(qǐng)求

? ? ? ? //? ? ? ? ? ? wx.request({

? ? ? ? //? ? ? ? ? ? ? ? url: 'http://localhost:28089/wxLogin',

? ? ? ? //? ? ? ? ? ? ? ? data: {

? ? ? ? //? ? ? ? ? ? ? ? ? ? code: res.code

? ? ? ? //? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log("123456")

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log(res);

? ? ? ? //? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? ? ? wx.getSetting({

? ? ? ? //? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log(res.authSetting);

? ? ? ? //? ? ? ? ? ? ? ? ? ? if (res.authSetting["scope.userInfo"]) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶已授權(quán)");

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? wx.getUserInfo({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log(res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exportJson.userInfo = res.userInfo;

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //此時(shí)可進(jìn)行登錄操作

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? let button = wx.createUserInfoButton({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? type: 'text',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? text: '',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? style: {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? left: 0,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? top: 0,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? width: width,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? height: height,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? backgroundColor: '#00000000',//最后兩位為透明度

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? color: '#ffffff',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fontSize: 20,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? textAlign: "center",

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lineHeight: height,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? button.onTap((res) => {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? if (res.userInfo) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶授權(quán):", res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exportJson.userInfo = res.userInfo;

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //此時(shí)可進(jìn)行登錄操作

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? button.destroy();

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶拒絕授權(quán):", res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? console.log('登錄失??!' + res.errMsg)

? ? ? ? //? ? ? ? }

? ? ? ? //? ? },

? ? ? ? // });

? ? },

? ? // /**

? ? //? * 手Q登錄? 官方文檔見https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_login.html#qq-login

? ? //? */

? ? qqLogin() {

? ? ? ? // let exportJson = {};

? ? ? ? // let sysInfo = qq.getSystemInfoSync();

? ? ? ? // //獲取微信界面大小

? ? ? ? // let width = sysInfo.screenWidth;

? ? ? ? // let height = sysInfo.screenHeight;

? ? ? ? // qq.login({

? ? ? ? //? ? success: (res) => {

? ? ? ? //? ? ? ? if (res.code) {

? ? ? ? //? ? ? ? ? ? console.log("獲取到的code:", res.code);

? ? ? ? //? ? ? ? ? ? exportJson.code = res.code;//向服務(wù)端傳遞code用于獲取微信小游戲的用戶唯一標(biāo)識(shí)

? ? ? ? //? ? ? ? ? ? //發(fā)起網(wǎng)絡(luò)請(qǐng)求

? ? ? ? //? ? ? ? ? ? qq.request({

? ? ? ? //? ? ? ? ? ? ? ? url: 'http://localhost:28089/qqLogin',

? ? ? ? //? ? ? ? ? ? ? ? data: {

? ? ? ? //? ? ? ? ? ? ? ? ? ? code: res.code

? ? ? ? //? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log("123456")

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log(res);

? ? ? ? //? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? ? ? qq.getSetting({

? ? ? ? //? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log(res.authSetting);

? ? ? ? //? ? ? ? ? ? ? ? ? ? if (res.authSetting["scope.userInfo"]) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶已授權(quán)");

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? qq.getUserInfo({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? success(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log(res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exportJson.userInfo = res.userInfo;

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //此時(shí)可進(jìn)行登錄操作

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? console.log("未授權(quán)")

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? let button = qq.createUserInfoButton({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? type: 'text',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? text: '',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? style: {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? left: 0,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? top: 0,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? width: width,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? height: height,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? backgroundColor: '#00000000',//最后兩位為透明度

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? color: '#ffffff',

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fontSize: 20,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? textAlign: "center",

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lineHeight: height,

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? button.onTap((res) => {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? if (res.userInfo) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶授權(quán):", res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? exportJson.userInfo = res.userInfo;

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //此時(shí)可進(jìn)行登錄操作

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? button.destroy();

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("用戶拒絕授權(quán):", res);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? } else {

? ? ? ? //? ? ? ? ? ? console.log('登錄失??!' + res.errMsg)

? ? ? ? //? ? ? ? }

? ? ? ? //? ? },

? ? ? ? // });

? ? },

? ? /**

? ? * 支付寶登錄? 官方文檔見https://opendocs.alipay.com/mini/api/openapi-authorize

? ? */

? ? aliLogin() {

? ? ? ? // my.getAuthCode({

? ? ? ? //? ? scopes: 'auth_user',

? ? ? ? //? ? success: (res) => {

? ? ? ? //? ? ? ? my.alert({

? ? ? ? //? ? ? ? ? ? content: res.authCode,

? ? ? ? //? ? ? ? });

? ? ? ? //? ? },

? ? ? ? // });

? ? },

? ? /**

? ? * OPPO登錄? 官方文檔見https://cdofs.oppomobile.com/cdo-activity/static/201809/30/gamehall/book/not_battle/readme.html#3-js-sdk

? ? */

? ? oppoLogin() {

? ? ? ? // OPPO.login({

? ? ? ? //? ? packageName: 'your.package.name', //需要修改成開發(fā)者在oppo開放平臺(tái)填寫的包名才能成功調(diào)用此方法

? ? ? ? //? ? callback: function(res) {

? ? ? ? //? ? ? ? console.log(res)

? ? ? ? //? ? }

? ? ? ? // })

? ? },

? ? /**

? ? * VIVO登錄? 官方文檔見https://minigame.vivo.com.cn/documents/#/api/service/newaccount?id=login

? ? */

? ? vivoLogin() {

? ? ? ? // if (qg.getSystemInfoSync().platformVersionCode >= 1053) {

? ? ? ? //? ? qg.login().then((res) => {

? ? ? ? //? ? ? ? if (res.data.token) {

? ? ? ? //? ? ? ? ? ? // 使用token進(jìn)行服務(wù)端對(duì)接

? ? ? ? //? ? ? ? }

? ? ? ? //? ? }, (err) => {

? ? ? ? //? ? ? ? console.log('登錄失敗' + JSON.stringify(err));

? ? ? ? //? ? });

? ? ? ? // }

? ? },

? ? // /**

? ? //? * 華為登錄? 官方文檔見https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickgame-api-account

? ? //? * @param {*} issafe 是否走防沉迷登錄

? ? //? */

? ? huaweiLogin(issafe) {

? ? ? ? // if (issafe) {

? ? ? ? //? ? console.log("普通游戲登錄")

? ? ? ? //? ? ? ? /**

? ? ? ? //? ? ? ? ? * 普通游戲登錄。

? ? ? ? //? ? ? ? ? */

? ? ? ? //? ? hbs.gameLogin({

? ? ? ? //? ? ? ? forceLogin: 1, //強(qiáng)制登錄,未登錄時(shí)會(huì)彈出登錄對(duì)話框

? ? ? ? //? ? ? ? appid: "102066507", //appid需要與華為開發(fā)者聯(lián)盟后臺(tái)配置一致

? ? ? ? //? ? ? ? success: function(res) {

? ? ? ? //? ? ? ? ? ? console.log("game login success");

? ? ? ? //? ? ? ? ? ? console.log("playerId是:" + res.playerId);

? ? ? ? //? ? ? ? ? ? console.log("displayName是:" + res.displayName);

? ? ? ? //? ? ? ? ? ? console.log("playerLevel是:" + res.playerLevel);

? ? ? ? //? ? ? ? ? ? console.log("isAuth是:" + res.isAuth);

? ? ? ? //? ? ? ? ? ? console.log("ts是:" + res.ts);

? ? ? ? //? ? ? ? ? ? console.log("gameAuthSign是:" + res.gameAuthSign);

? ? ? ? //? ? ? ? ? ? console.log("開發(fā)保存玩家信息+++++++++++++++++++++++");

? ? ? ? //? ? ? ? ? ? /***

? ? ? ? //? ? ? ? ? ? ? * 當(dāng)用戶完成選擇區(qū)服信息進(jìn)入游戲后,或者用戶的等級(jí)發(fā)生變化時(shí),游戲可以調(diào)用此接口存儲(chǔ)用戶的角色信息。如果游戲本身不具有游戲等級(jí)、角色名稱、游戲區(qū)服或者游戲公會(huì)這些信息則可以不接入此接口。

? ? ? ? //? ? ? ? ? ? ? */

? ? ? ? //? ? ? ? ? ? hbs.savePlayerInfo({

? ? ? ? //? ? ? ? ? ? ? ? appid: "102066507",

? ? ? ? //? ? ? ? ? ? ? ? area: "cn",

? ? ? ? //? ? ? ? ? ? ? ? rank: "1",

? ? ? ? //? ? ? ? ? ? ? ? role: "a",

? ? ? ? //? ? ? ? ? ? ? ? sociaty: "1",

? ? ? ? //? ? ? ? ? ? ? ? success: function(data) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log("DUWENJUN save player info success:" + res);

? ? ? ? //? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? fail: function(data, code) { console.log("DUWENJUN save player info fail:" + data + ", code:" + code); }

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: function(data, code) { console.log("DUWENJUN game login fail:" + data + ", code:" + code); }

? ? ? ? //? ? });

? ? ? ? // } else {

? ? ? ? //? ? console.log("防沉迷登錄")

? ? ? ? //? ? ? ? /**

? ? ? ? //? ? ? ? ? * 根據(jù)國家要求對(duì)未成年人的游戲時(shí)間進(jìn)行防沉迷監(jiān)控。調(diào)用此接口實(shí)現(xiàn)游戲登錄即可接入防沉迷的能力。

? ? ? ? //? ? ? ? ? */

? ? ? ? //? ? hbs.gameLoginWithReal({

? ? ? ? //? ? ? ? forceLogin: 1,

? ? ? ? //? ? ? ? appid: "102066507",

? ? ? ? //? ? ? ? success: function(res) {

? ? ? ? //? ? ? ? ? ? console.log("game login success");

? ? ? ? //? ? ? ? ? ? console.log("playerId是:" + res.playerId);

? ? ? ? //? ? ? ? ? ? console.log("displayName是:" + res.displayName);

? ? ? ? //? ? ? ? ? ? console.log("playerLevel是:" + res.playerLevel);

? ? ? ? //? ? ? ? ? ? console.log("isAuth是:" + res.isAuth);

? ? ? ? //? ? ? ? ? ? console.log("ts是:" + res.ts);

? ? ? ? //? ? ? ? ? ? console.log("gameAuthSign是:" + res.gameAuthSign);

? ? ? ? //? ? ? ? ? ? console.log("hiResImageUri是:" + res.hiResImageUri);

? ? ? ? //? ? ? ? ? ? console.log("imageUri是:" + res.imageUri);

? ? ? ? //? ? ? ? ? ? console.log("開發(fā)保存玩家信息+++++++++++++++++++++++");

? ? ? ? //? ? ? ? ? ? /***

? ? ? ? //? ? ? ? ? ? ? * 當(dāng)用戶完成選擇區(qū)服信息進(jìn)入游戲后,或者用戶的等級(jí)發(fā)生變化時(shí),游戲可以調(diào)用此接口存儲(chǔ)用戶的角色信息。如果游戲本身不具有游戲等級(jí)、角色名稱、游戲區(qū)服或者游戲公會(huì)這些信息則可以不接入此接口。該接口后續(xù)將代替 hbs.savePlayerInfo。

? ? ? ? //? ? ? ? ? ? ? */

? ? ? ? //? ? ? ? ? ? hbs.savePlayerInfoWithReal({

? ? ? ? //? ? ? ? ? ? ? ? area: "cn-1", // 玩家區(qū)服信息

? ? ? ? //? ? ? ? ? ? ? ? rank: "100", // 玩家等級(jí)

? ? ? ? //? ? ? ? ? ? ? ? role: "A11", // 角色名稱

? ? ? ? //? ? ? ? ? ? ? ? sociaty: "ss", // 游戲公會(huì)

? ? ? ? //? ? ? ? ? ? ? ? success: function(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log("save player info success");

? ? ? ? //? ? ? ? ? ? ? ? ? ? /**

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? * 獲取玩家?guī)鬒D。

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? */

? ? ? ? //? ? ? ? ? ? ? ? ? ? hbs.getCachePlayerId({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? success: function(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("game getCachePlayerId: success");

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("playerId是" + res.playerId);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? /**

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? * 獲取玩家的額外信息(僅支持中國大陸地區(qū)游戲)。

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? */

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? hbs.getPlayerExtraInfo({

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transactionId: "",

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? success: function(res) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("get player ExtraInfo success");

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("獲取玩家的額外信息成功:" + res.playerId);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fail: function(data, code) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("get player ExtraInfo fail:" + data + ", code:" + code);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? fail(data, code) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("on gameLoginWithReal fail: " + data + "," + code);

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? that.getLabel.string = data + ", " + code;

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? complete() {

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? ? ? console.log("on gameLoginWithReal: complete");

? ? ? ? //? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? ? ? },

? ? ? ? //? ? ? ? ? ? ? ? fail: function(data, code) {

? ? ? ? //? ? ? ? ? ? ? ? ? ? console.log("save player info fail:" + data + ", code:" + code);

? ? ? ? //? ? ? ? ? ? ? ? }

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: function(data, code) { console.log("DUWENJUN game login fail:" + data + ", code:" + code); },

? ? ? ? //? ? ? ? complete() { console.log("on gameLoginWithReal: complete"); }

? ? ? ? //? ? })

? ? ? ? // }

? ? },

? ? // /**

? ? //? *百度登錄? 官方文檔見https://smartprogram.baidu.com/docs/develop/api/open/log_swan-login/

? ? //? */

? ? baiduLogin() {

? ? ? ? ? ? // swan.login({

? ? ? ? ? ? //? ? success: res => {

? ? ? ? ? ? //? ? ? ? console.log("百度code是" + res.code);

? ? ? ? ? ? //? ? ? ? swan.request({

? ? ? ? ? ? //? ? ? ? ? ? url: 'http://localhost:28089/baiduLogin', // 開發(fā)者服務(wù)器地址

? ? ? ? ? ? //? ? ? ? ? ? data: {

? ? ? ? ? ? //? ? ? ? ? ? ? ? code: res.code

? ? ? ? ? ? //? ? ? ? ? ? }

? ? ? ? ? ? //? ? ? ? });

? ? ? ? ? ? //? ? },

? ? ? ? ? ? //? ? fail: err => {

? ? ? ? ? ? //? ? ? ? console.log('login fail', err);

? ? ? ? ? ? //? ? }

? ? ? ? ? ? // });

? ? },

? ? // /**

? ? //? * 小米登錄? 官方文檔見https://dev.mi.com/console/doc/detail?pId=1739#qgloginobject

? ? //? */

? ? xioamiLogin() {

? ? ? ? //? ? qg.login({

? ? ? ? //? ? ? ? success: function (res) {

? ? ? ? //? ? ? ? ? ? console.log(res.appAccountId)

? ? ? ? //? ? ? ? ? ? console.log(res.session)

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: function (res) { }

? ? ? ? //? ? });

? ? ? ? //? ? qg.getUserInfo({

? ? ? ? //? ? ? ? success: function (res) {

? ? ? ? //? ? ? ? ? ? console.log('nickName:${res.userInfo.nickName}')

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: function () {

? ? ? ? //? ? ? ? ? ? console.log('user reject!')

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? complete: function (res) {

? ? ? ? //? ? ? ? ? ? console.log('get userInfo complete')

? ? ? ? //? ? ? ? }

? ? ? ? //? ? });

? ? },

? ? // //微信支付? 官方文檔見https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html

? ? wxPay() {

? ? ? ? //? ? wx.requestPayment({

? ? ? ? //? ? ? ? timeStamp: '',

? ? ? ? //? ? ? ? nonceStr: '',

? ? ? ? //? ? ? ? package: '',

? ? ? ? //? ? ? ? signType: 'MD5',

? ? ? ? //? ? ? ? paySign: '',

? ? ? ? //? ? ? ? success(res) { },

? ? ? ? //? ? ? ? fail(res) { }

? ? ? ? //? ? })

? ? },

? ? // //手Q支付 官方文檔見https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_pay.html#qq-requestpayment

? ? qqPay() {

? ? ? ? //? ? qq.requestPayment({

? ? ? ? //? ? ? ? package: "prepay_id=" + 000,

? ? ? ? //? ? ? ? bargainor_id: "",

? ? ? ? //? ? ? ? success(res) { },

? ? ? ? //? ? ? ? fail(res) { }

? ? ? ? //? ? })

? ? },

? ? // //支付寶支付 官方文檔見https://opendocs.alipay.com/mini/api/openapi-pay

? ? aliPay() {

? ? ? ? //? ? my.tradePay({

? ? ? ? //? ? ? ? // 調(diào)用統(tǒng)一收單交易創(chuàng)建接口(alipay.trade.create),獲得返回字段支付寶交易號(hào)trade_no

? ? ? ? //? ? ? ? tradeNO: '201711152100110410533667792',

? ? ? ? //? ? ? ? success: (res) => {

? ? ? ? //? ? ? ? ? ? my.alert({

? ? ? ? //? ? ? ? ? ? ? ? content: JSON.stringify(res),

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: (res) => {

? ? ? ? //? ? ? ? ? ? my.alert({

? ? ? ? //? ? ? ? ? ? ? ? content: JSON.stringify(res),

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? }

? ? ? ? //? ? });

? ? },

? ? // //OPPO支付? 官方文檔見https://cdofs.oppomobile.com/cdo-activity/static/201809/30/gamehall/book/not_battle/readme.html#6-%E6%8C%A1%E6%9D%BF%E7%9A%84%E4%BD%BF%E7%94%A8

? ? oppoPay() {

? ? ? ? //? ? OPPO.pay({

? ? ? ? //? ? ? ? packageName: 'com.testgame.nearme.gamecenter', //開發(fā)者在oppo開放平臺(tái)填寫的包名

? ? ? ? //? ? ? ? appName: '游戲名稱',

? ? ? ? //? ? ? ? appVersion: '1.0',

? ? ? ? //? ? ? ? appKey: 'TESTOPPOPAY', //在oppo開放平臺(tái)得到的appKey

? ? ? ? //? ? ? ? orderId: '20171208001', //開發(fā)者在自己業(yè)務(wù)系統(tǒng)下的訂單號(hào)

? ? ? ? //? ? ? ? price: 1, //單位 分

? ? ? ? //? ? ? ? productName: '商品名稱',

? ? ? ? //? ? ? ? productDesc: '商品描述',

? ? ? ? //? ? ? ? callbackUrl: 'http: //www.yourdomain.com/notify',

? ? ? ? //? ? ? ? //接收支付平臺(tái)付款通知的地址,與oppo android SDK的支付通知處理一致

? ? ? ? //? ? ? ? callback: function (res) {

? ? ? ? //? ? ? ? ? ? console.log(res)

? ? ? ? //? ? ? ? }

? ? ? ? //? ? });

? ? },

? ? // //VIVO支付? 官方文檔見https://minigame.vivo.com.cn/documents/#/api/service/newpay

? ? vivoPay() {

? ? ? ? //? ? qg.pay({

? ? ? ? //? ? ? ? orderInfo: 'orderStr',

? ? ? ? //? ? ? ? success: function (ret) {

? ? ? ? //? ? ? ? ? ? qg.showToast({

? ? ? ? //? ? ? ? ? ? ? ? message: "支付成功:" + JSON.stringify(ret)

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: function (errmsg, errcode) {

? ? ? ? //? ? ? ? ? ? qg.showToast({

? ? ? ? //? ? ? ? ? ? ? ? message: "支付失?。? + errcode + ': ' + errmsg

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? complete: function () {

? ? ? ? //? ? ? ? ? ? qg.showToast({

? ? ? ? //? ? ? ? ? ? ? ? message: "支付完成"

? ? ? ? //? ? ? ? ? ? })

? ? ? ? //? ? ? ? }

? ? ? ? //? ? })

? ? },

? ? // //華為支付? 官方文檔見https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickgame-api-payment#hwPay

? ? huaweiPay() {

? ? ? ? //? ? hbs.hwPay({

? ? ? ? //? ? ? ? orderInfo: {

? ? ? ? //? ? ? ? ? ? "amount": 0.01,? //商品金額

? ? ? ? //? ? ? ? ? ? "applicationID": "100389777",? 應(yīng)用ID,在華為開發(fā)者聯(lián)盟上獲取的APP ID

? ? ? ? //? ? ? ? ? ? "productDesc": "商品描述",

? ? ? ? //? ? ? ? ? ? "productName": "商品名稱",

? ? ? ? //? ? ? ? ? ? "serviceCatalog": "X6",? //游戲設(shè)置為"X6",應(yīng)用設(shè)置為"X5"

? ? ? ? //? ? ? ? ? ? "merchantId": "10086000000000293",? //華為開發(fā)者聯(lián)盟上申請(qǐng)支付服務(wù)獲取的“支付ID“

? ? ? ? //? ? ? ? ? ? "merchantName": "商戶名稱",? //商戶名稱

? ? ? ? //? ? ? ? ? ? "sign": this.sign,? //簽名

? ? ? ? //? ? ? ? ? ? "requestId": this.requestid,? //在支付前生成,用于唯一標(biāo)識(shí)一次支付請(qǐng)求。支付平臺(tái)在服務(wù)器回調(diào)接口中會(huì)原樣返回requestId的值

? ? ? ? //? ? ? ? ? ? "urlver": "2",? //固定值為2

? ? ? ? //? ? ? ? ? ? "sdkChannel": 1,? // 1代表應(yīng)用市場(chǎng)渠道

? ? ? ? //? ? ? ? ? ? "publicKey": "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIL/7zgG9KCjm5IeGFzq8oVaxCqFJ9+m/3rGMXU2p9K+bHLPR1m3c9TMZRGjkZbTZ0G/VLPO6BxiP+w+VM+Z3fECAwEAAQ=="? //華為開發(fā)者聯(lián)盟上申請(qǐng)支付服務(wù)獲取的“支付公鑰”

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? success: function (ret) { console.log("pay success " + ret) },

? ? ? ? //? ? ? ? fail: function (erromsg, errocode) { console.log("pay fail : " + errocode + erromsg) }

? ? ? ? //? ? })

? ? },

? ? // //百度支付? 官方文檔見https://smartprogram.baidu.com/docs/develop/api/open/payment_swan-requestPolymerPayment/

? ? baiduPay() {

? ? ? ? //? ? // 這里只做字段展示,詳細(xì)示例請(qǐng)?jiān)诖a片段中查看

? ? ? ? //? ? swan.requestPolymerPayment({

? ? ? ? //? ? ? ? orderInfo: {

? ? ? ? //? ? ? ? ? ? "dealId": "470193086",

? ? ? ? //? ? ? ? ? ? "appKey": "MMMabc",

? ? ? ? //? ? ? ? ? ? "totalAmount": "1",

? ? ? ? //? ? ? ? ? ? "tpOrderId": "3028903626",

? ? ? ? //? ? ? ? ? ? "dealTitle": "智能小程序Demo支付測(cè)試",

? ? ? ? //? ? ? ? ? ? "signFieldsRange": "1",

? ? ? ? //? ? ? ? ? ? "rsaSign": '',

? ? ? ? //? ? ? ? ? ? "bizInfo": ''

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? success: res => {

? ? ? ? //? ? ? ? ? ? swan.showToast({

? ? ? ? //? ? ? ? ? ? ? ? title: '支付成功',

? ? ? ? //? ? ? ? ? ? ? ? icon: 'success'

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? },

? ? ? ? //? ? ? ? fail: err => {

? ? ? ? //? ? ? ? ? ? swan.showToast({

? ? ? ? //? ? ? ? ? ? ? ? title: JSON.stringify(err)

? ? ? ? //? ? ? ? ? ? });

? ? ? ? //? ? ? ? ? ? console.log('pay fail', err);

? ? ? ? //? ? ? ? }

? ? ? ? //? ? });

? ? },

? ? // //小米支付? 官方文檔見https://dev.mi.com/console/doc/detail?pId=1739#qgpayobject

? ? xioamiPay() {

? ? ? ? // qg.pay({

? ? ? ? //? ? orderInfo: {

? ? ? ? //? ? ? ? appId: "2882303761117490626",

? ? ? ? //? ? ? ? appAccountId: "74317",

? ? ? ? //? ? ? ? session: "TRQJzccscL9u6VvC",

? ? ? ? //? ? ? ? cpOrderId: '1556088963',

? ? ? ? //? ? ? ? cpUserInfo: '74317',

? ? ? ? //? ? ? ? displayName: '游戲元寶',

? ? ? ? //? ? ? ? feeValue: 100,

? ? ? ? //? ? ? ? sign: '22fea7804df43420dc9886a04c028b6f335d87b6',

? ? ? ? //? ? },

? ? ? ? //? ? success: function (data) {

? ? ? ? //? ? ? ? //{memo: "支付成功", resultStatus: "9000"}

? ? ? ? //? ? ? ? //9000: 支付成功

? ? ? ? //? ? },

? ? ? ? //? ? fail: function (data) {

? ? ? ? //? ? ? ? //{memo: "已取消支付", resultStatus: "6001"}

? ? ? ? //? ? ? ? //6001: 已取消支付

? ? ? ? //? ? ? ? //5000: 未安裝微信

? ? ? ? //? ? ? ? //5001: 微信訂單未支付

? ? ? ? //? ? }

? ? ? ? // })

? ? },

});


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容