微信小程序消息通知-打卡考勤

效果:

稍微改一下js就行,有不必要的错误,我就不改了,哈哈!

index.js

//index.js
const app = getApp()
// 填写微信小程序appid
var appid = '';
// 填写微信小程序secret
var secret = '';
Page({
// 页面数据
data: {
access_token: '',
openid: '',
}, // 表单请求
formRequst: function (e) {
var that = this;
// 登录
wx.login({
success: res => {
// 调用接口获取登录凭证(code)
console.log("获取code 成功", res.code);
var code = res.code;
// 获取openId
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&grant_type=authorization_code&js_code=' + code,
header: {
'content-type': 'application/json' //默认值
},
success: function (res) {
console.log("获取openid 成功", res.data.openid);
var openid = res.data.openid;
that.setData({
openid: openid
})
// wx.setStorageSync("openid", openid) // 获取 access_token
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + secret,
method: 'GET',
header: {
'content-type': 'application/json' //默认值
},
// 成功
success: function (res) {
console.log("获取小程序 access_token 成功", res.data.access_token);
that.setData({
access_token: res.data.access_token
}) // 上上一步
},
// 失败
fail: function (err) {
console.log("获取小程序 access_token 失败", err);
}
}) // 上一步
},
fail: function (err) {
console.log("获取openid 失败", err);
}
})
}
})
},
// 提交表单
formSubmit: function (e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value);
console.log('form发生了submit事件,携带数据为:', e.detail.formId); var that = this;
// 发送模板消息
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + that.data.access_token,
data: {
// openid
"touser": wx.getStorageSync("openid"),
// 模板消息的id
"template_id": "",
// "form_id": "FORMID",
"form_id": e.detail.formId,
data: {
"keyword1": {
"value": "2018.10.10"
},
"keyword2": {
"value": "小红"
}
},
"emphasis_keyword": "keyword1.DATA"
},
method: 'POST',
// 成功
success: function (res) {
var data = res.data;
console.log("sendTemplateMessage 成功", data);
wx.showToast({
title: '发送成功',
icon: 'success'
})
},
// 失败
fail: function (err) {
console.log("sendTemplateMessage 失败", err);
}
})
}, /**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.formSubmit();
}, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.formRequst();
}, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})

index.wxml

<!--index.wxml-->
<view class='page'>
<!-- 标题 -->
<view class='title'>
<text>考勤打卡</text>
</view>
<form class="text" report-submit="true" bindsubmit='formSubmit' bindreset='formReset'>
<!-- 考勤填表 -->
<input name="date" placeholder='日期' class='input'></input>
<input name="name" placeholder='姓名' class='input'></input>
<!-- 按钮设置 -->
<view class='btn'>
<button form-type='submit' type='primary'>提交</button>
<button form-type='reset' type='primary'>重置</button>
</view>
</form>
</view>

index.wxss

/**index.wxss**/

.page {
margin: 0rpx 50rpx 50rpx 50rpx;
font-size: 50rpx;
background-color: lavender;
} .title {
text-align: center;
} .input {
margin: 0rpx 0rpx 50rpx 0rpx;
width: 100%;
} .btn {
display: flex;
flex-direction: row;
}

往后余生,唯独有你

简书作者:达叔小生

90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通

简书博客: https://www.jianshu.com/u/c785ece603d1

结语

  • 下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注
  • 小礼物走一走 or 点赞

微信小程序消息通知-打卡考勤的更多相关文章

  1. 微信小程序--消息推送配置Token令牌错误校验失败如何解决

    微信开放第三方API接口, 申请地址: https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/inter ...

  2. 微信小程序之tabbar切卡

    最近在研究小程序的时候,遇到了一个问题,就是tabbar切卡,在android上有fragment,在RN上也有提供一个第三方的组件来用,微信小程序,好像没有专门的一个组件来实现这个功能,度娘了大半天 ...

  3. .NET CORE 微信小程序消息验证的坑

    进入微信小程序,点击开发->选择消息推送->扫码授权,填写必要参数 进入接口开发: /// <summary> /// 验证小程序 /// </summary> / ...

  4. 解决微信小程序ios端滚动卡顿的问题

    方案1:直接使用微信小程序提供的 “scroll-view " 组件. <scroll-view scroll-y style="height: 100%;"> ...

  5. Java实现 微信小程序 + 消息推送

    实现效果: 下面要显示五个字段 接下来,参照官方文档,一步步实现: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open- ...

  6. 微信小程序消息模板

    wxml: <form bindsubmit='sendSms' report-submit='true' id='fo'> <button form-type='submit'&g ...

  7. 微信小程序消息推送,前端操作

    <form bindsubmit="getFormId" report-submit="true"> <button form-type=&q ...

  8. 微信小程序-通知滚动小提示

    代码地址如下:http://www.demodashi.com/demo/14044.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  9. 微信小程序开发学习资料

    作者:初雪链接:https://www.zhihu.com/question/50907897/answer/128494332来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

随机推荐

  1. spring boot 源码分析

    说明:spring boot版本 2.0.6.RELEASE 思绪 首先,大家认识spring boot是从@SpringBootApplication注解和org.springframework.b ...

  2. Non-decreasing Array LT665

    Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...

  3. Echarts 在动态HTML报告中的应用

    # 参考官网 http://echarts.baidu.com/examples/ <scripts> <!--- echarts examples ---> </scr ...

  4. 描点的改进:运用chart画图。

    主要是利用Chart画图: 通过选中一部分曲线进行图像的放大和缩小,最小值为1格. 先计算最大值和最小差值.然后赋值给AxisY.Minimum 和AxisY.Maximum.x轴初始显示数目:Axi ...

  5. 洛谷P1386座位安排

    座位安排 今天,在机房里做了这道题目,我来整理一下思路. 首先读懂题意,这n个人是不需要按1到n来一次安排的,也就是说你可以先安排任意一个人. 那么有一种很好排除的情况,那就是对于大于等于i的作为的需 ...

  6. ffmpeg 推流相关指令

    1.rtsp->rtsp(只解封装,不解码) ffmpeg -re -rtsp_transport tcp -i rtsp://usr:passwd@ip:port/h264/ch1/sub/a ...

  7. Codeforces 888 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 G题 传送门 A题 传送门 题意简述:给一个数列,问有多少个峰值点(同时比两边都大/小的点) 思路:按照题意模拟. 代码: #include<bit ...

  8. Web打印控件Lodop实现表格物流单的打印

    Web打印控件Lodop实现表格物流单的打印 一.lodop打印预览效果图 LODOP.PRINT_SETUP();打印维护效果图 LODOP.PREVIEW();打印预览图 二.写在前面 最近项目用 ...

  9. JAVA执行远端服务器的脚本

    JAVA执行远端服务器的脚本 问题描述 实现思路 技术要点 代码实现 问题描述 工作中遇到这样一个问题,我们的应用为了实现高可用会采取双机部署,拓扑图大致如下: 这种方案可以简单的保证高可用,即便应用 ...

  10. java模板设计模式

    1.概述 模板设计模式定义:定义一个操作中的算法骨架,将步骤延迟到子类中. 模板设计模式是一种行为设计模式,一般是准备一个抽象类,将部分逻辑以具体方法或者具体的构造函数实现,然后声明一些抽象方法,这样 ...