123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- function ajax(opt) {
- opt = opt || {};
- opt.method = opt.method.toUpperCase() || 'POST';
- opt.url = opt.url || '';
- opt.async = opt.async || false;
- opt.data = opt.data || null;
- opt.success = opt.success || function() {};
- var xmlHttp = null;
- if (XMLHttpRequest) {
- xmlHttp = new XMLHttpRequest();
- } else {
- xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
- }
- var params = [];
- for (var key in opt.data) {
- params.push(key + '=' + opt.data[key]);
- }
- var postData = params.join('&');
- if (opt.method.toUpperCase() === 'POST') {
- xmlHttp.open(opt.method, opt.url, opt.async);
- xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
- xmlHttp.send(postData);
- } else if (opt.method.toUpperCase() === 'GET') {
- xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
- xmlHttp.send(null);
- }
- if (opt.async) {
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
- // 有传入success回调就执行
- opt.success(JSON.parse(xmlHttp.responseText));
- }
- }
- } else {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
- opt.success(JSON.parse(xmlHttp.responseText));
- }
- }
- };
- function wxShare(){
- //自定义微信分享
- var localUrl = encodeURIComponent(location.href.split('#')[0]);
- ajax({
- method: 'GET',
- url: 'https://logic.test.uqchat.cn/logic/signature',
- data: {
- url: localUrl
- },
- async: false,
- success: function(res) {
- //console.log(res)
- if(res.code == 200){
- //通过微信config接口注入配置
- wx.config({
- debug: false, // 默认为false 为true的时候是调试模式,会打印出日志
- appId: res.data.appid,
- timestamp: res.data.timestamp,
- nonceStr: res.data.noncestr,
- signature: res.data.signature,
- jsApiList: [
- 'checkJsApi',
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'onMenuShareQQ',
- 'onMenuShareWeibo',
- 'updateAppMessageShareData',
- 'updateTimelineShareData'
- ]
- });
- //配置自定义分享内容
- window.share_config = {
- 'share': {
- 'imgUrl': 'https://logic.test.uqchat.cn/partTimeJob/logo.png',
- 'desc': '测试有奖,丰富的聊天室玩法,欢迎有实力的公会入驻体验', // 这是分享展示的摘要
- 'title': '友期陪玩app,开测啦', // 这是分享展示卡片的标题
- 'link': location.href, // 这里是分享的网址
- 'success': function(rr) {
- console.log('成功' + JSON.stringify(rr))
- },
- 'cancel': function(tt) {
- console.log('失败' + JSON.stringify(tt));
- }
- }
- };
- wx.ready(function() {
- // wx.onMenuShareAppMessage(share_config.share); // 微信好友
- // wx.onMenuShareTimeline(share_config.share); // 微信朋友圈
- wx.updateAppMessageShareData(share_config.share); // 微信好友
- wx.updateTimelineShareData(share_config.share); // 微信朋友圈
- });
- }else{
- console.log(res)
- }
- }
- });
-
- }
- wxShare();
|