- openid返回值是什么?是null吗?
问题已解决,是用户名获取不到 ------------------------------------------------------------------------------------------------- 为什么头像拒绝读取的用户,依然可以跳转到下一页log呢?
2020-07-06 - openId,不让获取头像时,返回值 是null?
openId,不让获取头像时,返回值 是null?,应该不是,以null写的判断不起效
2020-07-06 - 提示:页面不存在?
1、ewm云函数 const cloud = require('wx-server-sdk') cloud.init({ env: 'xxxxxxxx' }) exports.main = async (event, context) => { try { const result = await cloud.openapi.wxacode.createQRCode({ path:event.urlname, //未验证 width: 410 }) const file = await cloud.uploadFile({ cloudPath: 'img.jpg', fileContent: result.buffer, }) return file } catch (err) { return err } } 2、index.js 调用代码 console.log('测试',dname) wx.cloud.callFunction({ //扫码传递参数pdname2(编号) name: "ewm", data: { urlname: '../tt index/index?dname=' + dname }, success: res =>{ console.log('test1',res.result) this.setData({ ima:res.result.fileID }) }, fail: err =>{ console.log() } }) 3、index.wmsl <view class="wm1"> <image style="width: 200px; height: 200px; background-color: #eeeeee;" src="{{ima}}"></image> </view> ------------------------------------------------------------------------------------------------- 另,有pages/tt index/index能访问。 扫码后,提示:页面不存在
2020-07-03 - 自定义tabbar 在电脑上运行正常,但真机调试时,出现错误?
1.新建template文件夹用于保存tabBar模板,template/template.wxml<template name="tabBar"> <view class="tabBar"> <block wx:for="{{tabBar}}" wx:for-item="item" wx:key="tabBar"> <view class="tabBar-item"> <navigator open-type="reLaunch" url="{{item.pagePath}}"> <view><image class="icon" src='{{item.iconPath}}'></image></view> <view class="{{item.current== 1 ? 'tabBartext' :''}}">{{item.text}}</view> </navigator> </view> </block> </view> </template> 2.创建template.wxss.icon{ width:54rpx; height: 54rpx; } .tabBar{ width:100%; position: fixed; bottom:0; padding:10rpx; margin-left:-4rpx; background:#F7F7FA; font-size:24rpx; color:#8A8A8A; box-shadow: 3rpx 3rpx 3rpx 3rpx #aaa; z-index: 9999; } .tabBar-item{ float:left; width:20%; text-align: center; overflow: hidden; } /*当前字体颜色*/ .tabBartext{ color:red; } .navigator-hover{ background-color: rgba(0, 0, 0, 0); } 3.创建template.js,初始化数据//初始化数据 function tabbarinit() { return [ { "current": 0, "pagePath": "/pages/dashboard/index", "iconPath": "/images/goback.png", "text": "返回商城" }, { "current": 0, "pagePath": "/pages/collage/index", "iconPath": "/images/collage1.png", "selectedIconPath": "/images/collage.png", "text": "拼团首页" }, { "current": 0, "selectedIconPath": "/images/list.png", "iconPath": "/images/list1.png", "pagePath": "/pages/collage-list/index", "text": "活动列表" }, { "current": 0, "selectedIconPath": "/images/collage-order.png", "iconPath": "/images/collage-order1.png", "pagePath": "/pages/collage-order/index", "text": "我的订单" }, { "current": 0, "selectedIconPath": "/images/group.png", "iconPath": "/images/group1.png", "pagePath": "/pages/group/index", "text": "我的团" } ] } //tabbar 主入口 function tabbarmain(bindName = "tabdata", id, target) { var that = target; var bindData = {}; var otabbar = tabbarinit(); otabbar[id]['iconPath'] = otabbar[id]['selectedIconPath']//换当前的icon otabbar[id]['current'] = 1; bindData[bindName] = otabbar that.setData({ bindData }); } module.exports = { tabbar: tabbarmain } 4.使用方法先把样式文件载入app.wxss@import "/template/template.wxss"; 新建一个页面,比如index.wxml,引入模板<import src="../../template/template.wxml"/> <template is="tabBar" data="{{tabBar:bindData.tabBar}}"/> index.js 初始化数据var template = require('../../template/template.js'); Page({ onLoad: function () { template.tabbar("tabBar", 0, this)//0表示第一个tabbar }, }) 其它新建页面也跟index.wxml一样,初始化数据。-------------------------------------------------------------------------------------------------------------------------------------------- 在电脑上运行正常,但真机调试时,出现错误: Error: module "template/template.js" is not defined
2020-07-02 - 与服务器通信,写入mysql数据库数据,写入不成功?
一、微信小程序 1、index.js const app = getApp() Page({ fortn: function () { //写入数据库 wx.request({ url: 'http://xxxxxxxxx/post.php', method: 'GET', data: { something1: '李四', something2: '25', something3: '0' }, header: { 'content-Type': 'application/x-www-form-urlencoded' }, success(res) { console.log(res.data); if (res.data.status == 0) { wx.showToast({ title: '提交失败!!!', icon: 'loading', duration: 1500 }) } else { wx.showToast({ title: '提交成功!!!', icon: 'success', duration: 1000 }) } } }); }, }) 2、index.wxml <button class="ff" bindtap='fortn' >增加</button> -------------------------------------------------------------- 二、服务器端 1、connect.php <?php //header("Content-type: text/html; charset=utf8"); //1. 声明字符编码 $host='127.0.0.1';//数据库ip $user='root';//用户名 $password='123456';//密码 $dbName='mymy';//要连接的数据库名 $con =new mysqli($host,$user,$password,$dbName,3308);//数据库连接 /*if ($con->connect_error) { echo "系统异常,连接数据库失败"; } else { echo "连接成功"; }*/ ?> 2、post.php <?php //header("Content-type: text/html; charset=utf8"); include 'connect.php';//调用connect.php文件 $something1=$_GET['something1'];//'小明';// $something2=$_GET['something2'];//'16';// $something3=$_GET['something3'];//'0';// if ($con->connect_error) { die("连接失败:".$con->connect_error); } else { $sql="INSERT INTO `doctor`(`name`, `age`, `xb`) VALUES ('$something1','$something2','$something3');"; $res=$con->query($sql); if($res){ $arr['status'] = 1; $arr['info'] = 'success'; }else{ $arr['status'] = 0; $arr['info'] = 'error'; } echo json_encode($arr); die; } ?> --------------------------------------------------- 三、mysql数据库名称为:mymy,表单是doctor,字段名称为`name`, `age`, `xb` ----------------------------------------------------------------------------- 增加数据不成功,不知为什么?(服务器http服务能访问到)
2020-06-28 - 云函数调用支付,怎样让支付窗口倒计时?
1、函数paypay const cloud = require('wx-server-sdk') cloud.init({ env: 'xxxxxxxx' }) exports.main = async (event, context) => { const res = await cloud.cloudPay.unifiedOrder({ "body" : "小秋TIT店-超市22", "outTradeNo" :event.outTradeNo, "spbillCreateIp" : "127.0.0.1", "subMchId" : "xxxxxxx", "totalFee" :event.totalFee, "envId": "xxxxxxxxx", "functionName": "pay", "nonceStr": event.nonceStr }) return res } 2、index.js Page({ onchick:function(){ var code=dkjfdkfjkdj var codestr=kdjfkdjfkjdflkjdfkjdfkj wx.cloud.callFunction({ name: 'paypay', data: { totalFee:5, outTradeNo:code, nonceStr: codestr }, success: res => { const payment = res.result.payment wx.requestPayment({ ...payment , success (res) { console.log('pay success', res) }, fail (res) { console.error('pay fail_1', err) } }) }, fail:console.log('pay fail_2'), }) } }) 3、index.wxml <button class="mf" ' bindtap='onchick'>支付</button> ------------------------------------------------------------------------------------------ 云函数调用支付成功,但怎样让支付浮窗倒计时呀?长时间不支付时,需要让浮窗消失,退出支付。
2020-06-27 - 为什么上传云函数会报错?
Error:更新云函数失败
2020-06-14 - 用云调用二维码后返回res.result.buffer,用云函数上传后返回显示不出来?
1、index.js Page({ onLoad: function (options) { console.log('test') wx.cloud.callFunction({ name: "yhs1", data: {}, success: res =>{ console.log('test2') console.log('test1',res.result.buffer) this.setData({ imaget:res.result.buffer }) }, fail: err =>{ console.log() } }) }, check: function () { var imaget=this.data.imaget console.log('test1',imaget) console.log('test') wx.cloud.callFunction({ name: "yhs2", data: { demo:imaget }, success: res =>{ console.log('test2') console.log('test1',res.result) this.setData({ imaget2:res.fiedId }) }, fail: err =>{ console.log() } }) } }) 2、index.wxml <image style="width: 200px; height: 200px; background-color: #eeeeee;" mode="{{item.mode}}" src="{{imaget2}}"></image> <view class="crr"> <button class="ff" bindtap='check'>test</button> </view> 3、云函数yhs1 // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: 'testw-z6k1v' }) exports.main = async (event, context) => { try { const result = await cloud.openapi.wxacode.createQRCode({ path: 'page/index/index', width: 430 }) return result } catch (err) { return err } } 4、云函数yhs2 // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: 'testw-z6k1v', }) exports.main = async (event, context) => { return await cloud.uploadFile({ cloudPath: 'demo.jpg', fileContent: event.demo }) } 运行后: {contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}buffer: ArrayBuffer(55707)[[Int8Array]]: Int8Array(55707) [-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, -1, -37, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, -1, -37, 0, 67, 1, 3, 4, 4, 5, 4, 5, …][[Uint8Array]]: Uint8Array(55707) [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, …]byteLength: (...)__proto__: ArrayBuffercontentType: "image/jpeg"errCode: 0errMsg: "openapi.wxacode.createQRCode:ok"__proto__: Object index.js:28 test1 {contentType: "image/jpeg", buffer: ArrayBuffer(55707), errMsg: "openapi.wxacode.createQRCode:ok", errCode: 0}
2020-06-12 - 获取二维码返回不正确?
//index.js //获取应用实例 const app = getApp() Page({ onLoad: function () { wx.request({ url: 'https://api.weixin.qq.com/cgi-bin/token', header: { 'content-type': 'application/json' }, data: { grant_type: 'client_credential', appid: 'XXXXX', secret: '秘钥' }, success(res) { var accessToken = res.data.access_token wx.request({ url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + accessToken, method: 'POST', responseType: 'arraybuffer', data: { "path": 'pages/index/index', "width": 430, }, success(res) { console.log(res.data) let base64 = wx.arrayBufferToBase64(res.data) console.log(base64) let codeImg = 'data:image/PNG;base64,' + base64 console.log(codeImg) }, }) } }) } }) -------------------------------------------------- 运行后返回的accessToken有问题: ArrayBuffer(112) {} eyJlcnJjb2RlIjo0MDAwMSwiZXJybXNnIjoiaW52YWxpZCBjcmVkZW50aWFsLCBhY2Nlc3NfdG9rZW4gaXMgaW52YWxpZCBvciBub3QgbGF0ZXN0IGhpbnRzOiBbaEtmQ0tuQUNlLXJTVG9fIV0ifQ== data:image/PNG;base64,eyJlcnJjb2RlIjo0MDAwMSwiZXJybXNnIjoiaW52YWxpZCBjcmVkZW50aWFsLCBhY2Nlc3NfdG9rZW4gaXMgaW52YWxpZCBvciBub3QgbGF0ZXN0IGhpbnRzOiBbaEtmQ0tuQUNlLXJTVG9fIV0ifQ==
2020-06-11 - 云函数查询云数据记录出错误?
1、云函数 name const cloud = require('wx-server-sdk') wx.cloud.init({ env: "xxxxxx" }) const db = cloud.database() exports.main = async (event, context) => { try { return await db.collection('gxser').doc('a85ed387c100134853').get() } catch (err) { console.log(err) } } 2、pages中的index.js Page({ onAdd:function() { wx.cloud.callFunction({ name: "name", success(res) { console.log("请求成功", res) }, fail(res) { console.log("请求失败", res) } }) } }) 3、index.wxml <button bindtap="onAdd">用函数</button> -------------------------------------------------------------------------------------------- 运行提示: 请求失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID b5007aac-a98c-11ea-922e-5254001dad8e, cloud function service error code -504002, error message wx is not defined; at cloud.callFunction api; at new u (VM319 WAService.js:2) at d (VM319 WAService.js:2) at f (VM319 WAService.js:2) at Function.success (VM319 WAService.js:2) at VM319 WAService.js:2 at T (VM319 WAService.js:2) at i.<anonymous> (VM319 WAService.js:2) at i.emit (VM319 WAService.js:2) at Si (VM319 WAService.js:2) at VM319 WAService.js:2
2020-06-08