微信分享和釘釘分享實例


最近公司做了一個小游戲.豫園老廟黃金的客戶要求分享到微信和釘釘.做的時候雖然簡單.還是發現了許多小問插曲,希望給需要的人幫助.分享出來.在blog里面編輯代碼哪位知道,格式化代碼如何用?

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

<script type="text/javascript" src="http://g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>


function isWeiXin() {

  //判斷是否微信
  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;
  }
}

/***微信分享***/
$.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(){

  //判斷是不是釘釘
  var ua = navigator.userAgent.toLowerCase();
  return ua.indexOf("dingtalk") >= 0;
}

/*點擊我要分享button*/

$("#shareit").on("click", function(){
  $("#shareit").hide();
})

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) {}
  });
})
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM