现在的位置: 首页 > 微信开发 > 正文

微信分享成功的js写法(seajs中AMD的模块管理)

2016年04月22日 微信开发 ⁄ 共 1646字 ⁄ 字号 评论关闭

HTML代码为:

<script>
var shareTitle="帮我投票,送我去英国和安迪科尔共进Low tea!";
var shareDescription='帮我投票,送我去英国和安迪科尔共进Low tea!';
var shareUrl='<?php echo wx_share['url']; ?>';
var shareImage='http://7xsqmh.com2.z0.glb.clouddn.com/images/logo_4.png';
var urls=location.href.split('#')[0];
var e=encodeURIComponent(urls);
</script>
<script>seajs.use("js/share_wx");</script>
<script>
  seajs.use('jquery',function(){
    ('#idFinish_wx').click(function(){
       ('.brok_pack').fadeIn(200);
       (this).addClass('idwapimg');
    });
    ('.brok_pack').click(function(){
      (this).fadeOut(200);
      ('#idFinish_wx').removeClass('idwapimg');
    })
  })
</script>
<script>
function sharesucess(){
  window.location.href=cid_url+'/api/wx_activity/cole_over';
}
</script>

JS代码为:

define("js/share_wx",["jquery","http://res.wx.qq.com/open/js/jweixin-1.0.0.js"],function(a){
    "user strict";var =a("jquery");var wx=a('http://res.wx.qq.com/open/js/jweixin-1.0.0.js');
.ajax({
  type:"GET",
  url:"http://wx.5usport.com/Jsapisign",
  data:{signurl:e},
  dataType:"json",
  success:function(e){
    //alert(e.appid);
    wx.config({
      debug:!1,
      appId:e.appid,
      timestamp:e.timestamp,
      nonceStr:e.noncestr,
      signature:e.signature,
      jsApiList:["checkJsApi","onMenuShareTimeline","onMenuShareAppMessage"]
      })
    },
  error:function(){
    alert("数据有误!")}
})

wx.ready(function(){
  wx.showOptionMenu(),
  wx.onMenuShareAppMessage({
    title:shareTitle,
    desc:shareDescription,
    link:shareUrl,
    imgUrl:shareImage,
    trigger:function(e){},
    success:function(e){
      sharesucess();
    },
    cancel:function(e){},
    fail:function(e){}
  })
  wx.onMenuShareTimeline({
    title:shareTitle,
    link:shareUrl,
    imgUrl:shareImage,
    trigger:function(e){},
    success:function(e){
      sharesucess();
    },
    cancel:function(e){},
    fail:function(e){}
  })
})
wx.error(function(e){
  alert(e.errMsg)
});

});

这样调用是很成功的

抱歉!评论已关闭.

×