<?php require_once "weixin.php"; $jssdk = new JSSDK(appId, appSecretecret); $signPackage = $jssdk->GetSignPackage(); class Config{ var $appId; var $timestamp; var $nonceStr; var $signature; var $url; } $config = new Config(); $config -> appId = $signPackage["appId"]; $config -> timestamp = $signPackage["timestamp"]; $config -> nonceStr = $signPackage["nonceStr"]; $config -> signature = $signPackage["signature"]; $config -> url = $signPackage["url"]; echo json_encode($config); ?>
getconfig.js 使用ajax获取接口数据(配置参数)
var getConfig = function(callback) { $.ajax({ url: "http://www.goxueche.com/api/configdata.php", type: "get", success: function(data) { callback(data); } }) } module.exports = getConfig;
share.js 分享函数
var getWeixincofig = require("./getconfig.js"); getWeixincofig(shareweixin); function shareweixin(data) { var data = JSON.parse(data); console.log(data); window.wx.config({ debug:true, appId: data.appId, timestamp: data.timestamp, nonceStr: data.nonceStr, signature: data.signature, jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage'] }); wxShare(); } function wxShare() { //检测api是否生效 wx.ready(function() { wx.checkJsApi({ jsApiList: [ 'getNetworkType', 'previewImage' ], success: function(res) { console.log(JSON.stringify(res)); } }); //分享给好友 wx.onMenuShareAppMessage({ title: '趣学车-有温度的互联网驾校', desc: '想去学车,就趣学车!', link: 'http://www.goxueche.com', imgUrl: 'http://www.goxueche.com/....png' }); //分享到朋友圈 wx.onMenuShareTimeline({ title: '趣学车-有温度的互联网驾校', desc: '想去学车,就趣学车!', link: 'http://www.goxueche.com', imgUrl: 'http://www.goxueche.com/....png' }); }); }
webpack.config.js
var webpack = require('webpack'); module.exports = { entry: { index: './share.js', }, output: { path: './', filename: '[name].js' } };
本文已被整理到了《JavaScript微信开发技巧汇总》,欢迎大家学习阅读。
为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。