import { init, loginUserInfo, dataReport, makePayment, shareAppMessage, payConfig, navigateToMiniProgram, getBindPhoneCode, bindPhone, onShareAppMessage, requestSubscribeMessage, triggerSubscribe, createAd, login, secCheckText, secCheckMedia, } from "./dist/rywxsdk.1.0.3.js"; // } from "./index"; // 初始化skd (async () => { try { let data = { app_version: "1.0.1", config_id: "wxa0167e87cc5efae3", //测试号id game_name: "逍遥志", }; // 静默授权 const res = await init(data); console.log(res); // 非静默授权 // const buttonStyle = { // type: 'text', // text: '点击进入游戏', // style: { // left: 10, // top: 76, // width: 200, // height: 40, // lineHeight: 40, // backgroundColor: '#ff0000', // color: '#FFFFFF', // textAlign: 'center', // fontSize: 16, // borderRadius: 4 // }, // withCredentials: true // } // await init(data,buttonStyle); wx.showToast({ title: "进入游戏成功", }); //拉起订阅 await requestSubscribeMessage(); //触发订阅 await triggerSubscribe("login"); } catch (error) { console.log(error); } })(); //角色上报按钮 const handleDataReport = async () => { try { let info = { data_type: 2, server_id: 1, server_name: "测试1服", role_id: "10000111", role_name: "小林", role_level: 1, role_currency: "", game_fee: "" }; const res = await dataReport(info); wx.showToast({ title: "角色上报成功", }); console.log(res); } catch (error) { console.log(error); } }; //展示下单按钮 const handleMakePayment = async () => { try { let info = { amt: 1, server_id: 1, server_name: "测试1服", role_id: "10000111", role_name: "小林", role_level: 1, ext: String(new Date().getTime()), product_id: 1, product_name: "测试商品" }; wx.showToast({ title: "拉起订单成功", }); makePayment(info) .then((res) => { if (res && Object.keys(res).length) { console.log("下单类型返回", res); } }) .catch((error) => { console.log(error); // 如果是节流错误,显示友好提示 if (error.message === "请求过于频繁,请稍后再试") { wx.showToast({ title: "操作过于频繁,请稍后再试", icon: "none", }); } }); } catch (error) { console.log(error); } }; const handleMakePayment2 = async () => { try { let info = { amt: 2, server_id: 1, server_name: "测试1服", role_id: "10000111", role_name: "小林", role_level: 1, product_id: 1, product_name: "测试1服", ext: "aaaaaaa", }; wx.showToast({ title: "拉起订单成功", }); makePayment(info) .then((res) => { if (res && Object.keys(res).length) { console.log("下单类型返回", res); } }) .catch((error) => { console.log(error); // 如果是节流错误,显示友好提示 if (error.message === "请求过于频繁,请稍后再试") { wx.showToast({ title: "操作过于频繁,请稍后再试", icon: "none", }); } }); } catch (error) { console.log(error); } }; //主动分享 const handleShareAppMessage = async () => { try { let info = { title: "分享测试", imageUrl: "https://api-user.91fengwan.com/hd/img/632-2.jpg", ext: "&ceshi=linquan321", }; await shareAppMessage(info); wx.showToast({ title: "分享成功", }); } catch (error) { console.log(error); } }; // 登录 const handleLogin = async () => { try { const res = await login(); console.log("登录返回res", res); } catch (error) { console.log(error); } }; //获取平台登录用户信息 const handleLoginUserInfo = async () => { try { const res = await loginUserInfo(); console.log(res); wx.showToast({ title: "获取成功", }); } catch (error) { console.log(error); } }; //IOS 获取获取是否开启支付接口 const handlePayConfig = async () => { try { const res = await payConfig() .then((res) => { }) .catch((error) => { }); console.log(res); wx.showToast({ title: "获取成功", }); } catch (error) { console.log(error); } }; //展示跳转小程序按钮 const handleNavigateToMiniProgram = async () => { try { await navigateToMiniProgram(); wx.showToast({ title: "打开成功", }); } catch (error) { console.log(error); } }; //展示获取短信 const handleGetBindPhoneCode = async () => { try { const res = await getBindPhoneCode({ phone: "15975492315", }); console.log(res) wx.showToast({ title: "发送成功", }); } catch (error) { wx.showToast({ title: error.msg, }); console.log(error); } }; //展示绑定手机 const handleBindPhoneCode = async () => { try { let info = { phone: "15975492315", code: "101344", }; await bindPhone(info); wx.showToast({ title: "绑定成功", }); } catch (error) { wx.showToast({ title: error.msg, }); console.log(error); } }; //主动监听 const handleOnShareAppMessage = () => { onShareAppMessage({ title: "测试", imageUrl: "https://api-user.91fengwan.com/hd/img/632-2.jpg", ext: "&ceshi=test", }); }; //获取订阅 const handleRequestSubscribeMessage = async () => { try { const res = await requestSubscribeMessage(); // await triggerSubscribe('login'); wx.showToast({ title: "获取成功", }); // console.log(res) } catch (error) { console.log(error); } }; //创建广告 const handleCreateAd = async () => { try { const res = await createAd({ ad_type: "video", task: "123", }); console.log(res); } catch (error) { console.log(error); } }; //文本内容安全检测 const handleSecCheckText = async () => { try { const res = await secCheckText({ content: "毛泽东真厉害", scene: 1 }); console.log(res); } catch (error) { console.log(error); } }; //多媒体内容安全检测 const handleSecCheckMedia = async () => { try { const res = await secCheckMedia({ media_url: "https://api-user.91fengwan.com/hd/img/632-2.jpg", media_type: "image", scene: "123", }); console.log(res); } catch (error) { console.log(error); } }; function newButtonMap(name, callback, x, y, w = 200, h = 30) { return { name: name, callback: callback, x: x, y: y, w: w, h: h, }; } let buttonList = [ newButtonMap("登录", handleLogin, 10, 60), newButtonMap("上报用户角色", handleDataReport, 10, 450), newButtonMap("生成1元订单", handleMakePayment, 10, 500), newButtonMap("生成2元订单", handleMakePayment2, 10, 540), newButtonMap("主动分享", handleShareAppMessage, 10, 90), newButtonMap("获取平台登陆用户信息", handleLoginUserInfo, 10, 130), newButtonMap("IOS获取获取是否开启支付", handlePayConfig, 10, 170), newButtonMap("跳转小程序", handleNavigateToMiniProgram, 10, 210), newButtonMap("获取手机验证码", handleGetBindPhoneCode, 10, 250), newButtonMap("绑定手机", handleBindPhoneCode, 10, 290), newButtonMap("监听分享传参", handleOnShareAppMessage, 10, 330), newButtonMap("获取订阅", handleRequestSubscribeMessage, 10, 370), newButtonMap("创建广告", handleCreateAd, 10, 410), newButtonMap("文本内容安全检测", handleSecCheckText, 10, 600), newButtonMap("多媒体内容安全检测", handleSecCheckMedia, 10, 640), ]; const canvas = wx.createCanvas(); const ctx = canvas.getContext("2d"); ctx.fillStyle = "#ff0000"; ctx.font = "14px Arial"; ctx.strokeStyle = "#ff0000"; for (let k in buttonList) { // ctx.fillRech(0,0,200,40) // let path = new Path2D() // path.rect(buttonList[k].x, buttonList[k].y, buttonList[k].w, buttonList[k].h); // ctx.stroke(path) ctx.fillText(buttonList[k].name, 20, buttonList[k].y + 20); } wx.onTouchStart(function (a) { let cur = a.touches[0]; for (let k in buttonList) { if ( cur.clientX >= buttonList[k].x && cur.clientX <= buttonList[k].x + buttonList[k].w && cur.clientY >= buttonList[k].y && cur.clientY <= buttonList[k].y + buttonList[k].h ) { buttonList[k].callback(); } } });