最近公司作了一个小游戏.豫园老庙黄金的客户要求分享到微信和钉钉.作的时候虽然简单.仍是发现了许多小问插曲,但愿给须要的人帮助.分享出来.在blog里面编辑代码哪位知道,格式化代码如何用?javascript
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>html
<script type="text/javascript" src="http://g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>java
function isWeiXin() {web
//判断是否微信
var ua = window.navigator.userAgent.toLowerCase();
console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true;
} else {
return false;
}
}json
/***微信分享***/
$.getJSON("http://mall.laomiao.com.cn/gold/webapp/main/js_sdk_config.do?jsoncallback=?", function(data){
data.jsApiList = [
"onMenuShareTimeline",
"onMenuShareAppMessage"
];
wx.config(data);
wx.ready(function(){
//分享给朋友
wx.onMenuShareAppMessage({
title: '测五行,拿好运大礼',
desc: '我刚刚在老庙黄金测算狗年五行属性,超准哦!',//这里请特别注意是要去除html
link: location.href+'&share=1',
imgUrl: 'http://mall.laomiao.com.cn/gold/res/activity-zodiac/images/turntable.png',
success: function (data) {
},
fail: function () {
}
});
//分享到朋友圈
wx.onMenuShareTimeline({
title: '测五行,拿好运大礼',
desc: '我刚刚在老庙黄金测算狗年五行属性,超准哦!',//这里请特别注意是要去除html
link: location.href+'&share=1',
imgUrl: 'http://mall.laomiao.com.cn/gold/res/activity-zodiac/images/turntable.png',
success: function () {
},
fail: function () {
}
});
});
wx.error(function (res) {alert(JSON.stringify(res));})
})微信
/*钉钉分享*/
function isdingding(){app
//判断是否是钉钉
var ua = navigator.userAgent.toLowerCase();
return ua.indexOf("dingtalk") >= 0;
}webapp
/*点击我要分享button*/iphone
$("#shareit").on("click", function(){
$("#shareit").hide();
})ide
function shareshow(){
if(isWeiXin()){
$("#shareit").show();
}else if(isdingding()){
dd.ready(function() {
dd.biz.util.share({
type: 0, //分享类型,0:所有组件 默认; 1:只能分享到钉钉;2:不能分享,只有刷新按钮
url: window.location.href + '&share=1',
content: '我刚刚在老庙黄金测算狗年五行属性,超准哦!',
title: '测五行,拿好运大礼',
image: 'http://mall.laomiao.com.cn/gold/res/activity-zodiac/images/turntable.png',
onSuccess: function() {
//onSuccess将在分享完成以后回调
/**/
},
onFail: function(err) {}
})
});
}
}
/*进入页面自动加载分享内容*/
if(isdingding()){ dd.ready(function(){ dd.biz.navigation.setRight({ show: true,//控制按钮显示, true 显示, false 隐藏, 默认true control: true,//是否控制点击事件,true 控制,false 不控制, 默认false text: '分享',//控制显示文本,空字符串表示显示默认文本 onSuccess : function(result) { //若是control为true,则onSuccess将在发生按钮点击事件被回调 dd.biz.util.share({ type: 0, //分享类型,0:所有组件 默认; 1:只能分享到钉钉;2:不能分享,只有刷新按钮 url: window.location.href + '&share=1', content: '我刚刚在老庙黄金测算狗年五行属性,超准哦!', title: '测五行,拿好运大礼', image: 'http://mall.laomiao.com.cn/gold/res/activity-zodiac/images/turntable.png', onSuccess: function() {}, onFail: function(err) {} }) }, onFail : function(err) {} }); }) }