uni-app 封装企业微信config
第一步,在项目根目录加一个html文件,
index.html 代码如下:
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><title><%= htmlWebpackPlugin.options.title %></title><script>document.addEventListener('DOMContentLoaded', function() {document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'})</script><link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" /><script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script><script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id="app"></div><!-- built files will be auto injected --></body>
</html>
点击 manifest.json 配置路径
在util新增 wechat.js ,代码如下:(这个js的工作就是初始化企业微信 js-sdk)
const API = require("./api.js")
//由于企业微信jssdk不是模块化js文件,所以采用自定义index.html模板,并用<script>标签引入
// const jWeixin = require('../static/jweixin-1.2.0.js');const initJssdk = function() {return new Promise((reslove, reject) => {API.getConfig({url: encodeURIComponent(window.location.href.split('#')[0])}).then(res => {if (res.success) {let info = JSON.parse(res.module.config);jWeixin.config({beta: info.beta, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题debug: info.debug, // 开启调试模式appId: info.appId, // 必填,企业微信的corpIDtimestamp: info.timestamp, // 必填,生成签名的时间戳nonceStr: info.nonceStr, // 必填,生成签名的随机串signature: info.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法jsApiList: ['shareToExternalContact'] || info.jsApiList // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来});jWeixin.ready((res) => {console.log('config初始化成功');reslove(true)})jWeixin.error(function(res) {console.log('config初始化失败', res);reslove(false)});} else {reslove(false)}})})
}module.exports = {initJssdk
}
使用方式
import wechat from "../../utils/wechat.js"
export default {
onLoad() {wechat.initJssdk().then(next => {if (next) console.log("initJssdk成功")})
},
methods: {jWeixin.onMenuShareAppMessage({title: '', // 分享标题desc: '', // 分享描述link: '', // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致imgUrl: '', // 分享图标success: function () {// 用户确认分享后执行的回调函数},cancel: function () {// 用户取消分享后执行的回调函数}});
}
}
完成
相关文章:

sqoop架构_SQOOP架构的深入介绍
sqoop架构by Jayvardhan Reddy通过杰伊瓦尔丹雷迪(Jayvardhan Reddy) SQOOP架构的深入介绍 (An in-depth introduction to SQOOP architecture) Apache Sqoop is a data ingestion tool designed for efficiently transferring bulk data between Apache Hadoop and structure…

JS实现录音,播放完整代码带示例图
效果图: 实现代码: <!DOCTYPE html> <html><head><script src"recorder.js" type"text/javascript" charset"utf-8"></script><meta name"viewport" content"widthdevi…

r.json()
requests模块中,r.json()为Requests中内置的JSON解码器 其中只有response返回为json格式时,用r.json()打印出响应的内容, 如果response返回不为json格式,使用r.json()会报错 报错内容:ValueError: Expecting property …

冒泡排序语法树
转载于:https://www.cnblogs.com/alfredzhu/p/4939268.html

valve 的设计_向Valve Portal开发人员学习游戏设计原则
valve 的设计In this talk, Valve programers who created the game Portal discuss problems they faced in development and how they solved them. Leaning about how they solved Portal problems can give you insight into how to design better games.在本次演讲中&…

Android之控件使用
Android系统为我们提供了大量的控件,例如:开关控件、单选按钮、多选按钮、单选菜单等等,那么这些控件如何使用呢?本篇我将带领大家一道学习一下如何使用这些控件。所谓无图无真相,先让大家看一下效果图: 下…

《对软件工程课程的期望》
要学习到的能力的预期:要学会个人,结对,团队的代码编辑流程,学会和别人进行交流。 对项目课程的期望:希望不是枯燥的代码详解。 对项目的愿景规划:希望团队里的每个人都能学到有用的知识。转载于:https://w…

HTML发送语音,上传音频PHP接收
实现需求:网页录制音频上传给后端接收,接收后PHP把文件的名字存到数据库的表里面,这里我的后端用的是PHP,并且把代码贴出来了。 前端实现代码: <!DOCTYPE HTML> <html><head><meta http-equiv&q…

html:漂亮的原生表格_HTML表格:关于它们的所有知识
html:漂亮的原生表格by Alexander Gilmanov亚历山大吉尔马诺夫(Alexander Gilmanov) HTML表格:关于它们的所有知识 (HTML Tables: All there is to know about them) Judging by the fact that we created wpDataTables, it’s no secret that we like tables. So …

[BZOJ] 1606: [Usaco2008 Dec]Hay For Sale 购买干草
1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1335 Solved: 989[Submit][Status][Discuss]Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤…

PHP TP5框架 安装运行 Warning: require(E:\phpstudy_pro\WWW\TP5\tp5\public/../thinkphp/base.php): failed to
创建一个新的项目:进入项目的根目录执行 git 命令: 先执行 git clone -b 5.1 https://git.coding.net/liu21st/thinkphp5.git tp5 进入 tp5目录 cd tp5再执行 git clone -b 5.1 https://git.coding.net/liu21st/framework.git thinkphp 执行更新框…

python之模块base64
# -*- coding: cp936 -*- #python 27 #xiaodeng>>> help(base64) #用来作base64编码解码 FUNCTIONS #函数(功能) •b16decode(s, casefoldFalse)Decode a Base16 encoded string. #解码 decode_stringbase64…

github pages_使用GitHub Pages和Lighthouse增强您的开发人员产品组合
github pagesFor someone who is trying to break into software development, it doesn’t matter where you look — LinkedIn, career advice boards, youtube tutorials — the advice is always the same: you need a portfolio. freeCodeCamp knows this advise, and the…

Angular 4+ HttpClient
个人博客迁移至 http://www.sulishibaobei.com 处; 这篇,算是上一篇Angular 4 Http的后续; Angular 4.3.0-rc.0 版本已经发布?。在这个版本中,我们等到了一个令人兴奋的新功能 - HTTPClient API 的改进版本; HttpCli…

PHP TP5入门 二:写接口,添加控制器并访问
默认访问地址:http://localhost/TP5/tp5/public/index.php/index/hello_world 实现代码: <?php namespace app\index\controller;class HelloWorld {public function index(){return 22hello,world!;} } 添加一个控制器如…

Possion 分布
泊松分布的概率函数为: \[P(Xk)\frac{\lambda^k}{k!}e^{-\lambda},k0,1,2,\cdots\] 如果 $X_i \sim P(\lambda_i)$,并且 互相独立,那么: \[Y\left( \sum\limits_{i1}^n{X_i} \right) \sim P \left( \sum\limits_{i1}^n{\lambda_i} \right)\] 从上面公式…

如何使您的Kotlin Android动画可访问
When researching examples for a first ever Android contribution, few examples existed for animations written in Kotlin. There were also few code examples of accessibility considerations within native animations.在研究有史以来第一个Android贡献的示例时&#…

指针空间的申请与释放
一、malloc()和free()的基本概念以及基本用法: 1、函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针。如果分配失败,则返回一个空指针(NULL࿰…

UIGraphicsBeginImageContext - 位图上下文
UIGraphicsBeginImageContext 首先,先来认识一个UIGraphicsBeginImageContext,它会创建一个基于位图的上下文(context)(默认创建一个透明的位图上下文),并将其设置为当前上下文。 位图图形上下文UIKit是不会负责创建的,…

小程序双击事件
代码: <button data-time"{{lastTapTime}}" data-title"标题" bindtap"doubleClick">双击</button> js data: {lastTapTime:0,}, doubleClick: function (e) {var curTime e.timeStampvar lastTime e.currentTarget…

快速了解Kubernetes微服务中的通信
by Adam Henson亚当汉森(Adam Henson) 快速了解Kubernetes微服务中的通信 (A quick look at communication in Kubernetes microservices) “服务”概念和一个Node.js示例 (The “service” concept and a Node.js example) Based on complexity, a layer of microservices ca…

连接 linux服务器
操作步骤: xshell 下载 https://xshell.en.softonic.com/ 点击下载后,会有邮箱验证,点击验证通过就会自动下载,然后安装就行。 打开工具,点击新建会话 然后 浏览文件后直接点击确认,出来这样就登录成功了…

【bzoj3924】[Zjoi2015]幻想乡战略游戏 动态点分治
题目描述 傲娇少女幽香正在玩一个非常有趣的战略类游戏,本来这个游戏的地图其实还不算太大,幽香还能管得过来,但是不知道为什么现在的网游厂商把游戏的地图越做越大,以至于幽香一眼根本看不过来,更别说和别人打仗了。 …

面试题05-UI控件
怎么解决缓存池满的问题(cell)ios中不存在缓存池满的情况,因为通常我们ios中开发,对象都是在需要的时候才会创建,有种常用的说话叫做懒加载,还有在UITableView中一般只会创建刚开始出现在屏幕中的cell,之后都是从缓存池…

全球链界科技发展大会_如何成为科技界的团队合作者
全球链界科技发展大会by Ofer Vugman由Ofer Vugman 如何成为科技界的团队合作者 (How to be a team player in the tech world) 这些技巧将增进您的关系并提高团队的工作效率 (These tips will boost your relationships and your team’s efficiency at work) When I landed …

linux驱动之i2c子系统mpu6050设备驱动
以下是mpu6050简单的驱动实现,mpu6050是I2C接口的6轴传感器,可以作为字符设备注册到内核,本代码运行环境是3.4.2内核,4.3.2版本的编译链,12.04版本的Ubuntu,硬件环境是jz2440开发板; 按照之前分…

小程序使用富文本完整代码及示例图
先看示例图: 富文本html代码: 效果图: 实现步骤: 1.下载 wxParse代码放到你的小程序项目目录里面 https://github.com/icindy/wxParse 基本使用方法 Copy文件夹wxParse - wxParse/-wxParse.js(必须存在)-html2json.js(必须存在…

C# 百分比的获取
这里介绍 C# 百分比转换有2种方式 例: double a50; double b100; a/b.ToString("0.00%"); 或 a/b.ToString("P3"); p后的数字表示能显示小数点后几位的精度数 实际如: 方法一:a/b.ToString("0.00%"); 方法二&a…

css 网格布局_我从CSS网格布局中学到的东西
css 网格布局by Jennifer Wjertzoch珍妮弗维佐奇 我从CSS网格布局中学到的东西 (Things I’ve learned about CSS grid layout) With CSS Grid you can create complex web designs. It is very intuitive and very well supported by the major browsers. In this article I …
GoF23种设计模式之行为型模式之解释器模式
一、概述 给定一种语言和其文法的一种表示,再定义一个解释器,该解释器使用表示来解释语言中的句子。 二、适用性 当需要解释一种语言,并且可以将该语言中的句子表示为一个抽象语法树的时候。 1.该文法简单对于复杂的文法&…