• 微信页面的分享,设置分享信息以及监听分享


    js端

    <script src=http://res.wx.qq.com/open/js/jweixin-1.0.0.js></script>
    
    //配置微信分享
    wx.config({
      debug: false,
      appId: '<?php echo $signPackage["appId"];?>',
      timestamp: '<?php echo $signPackage["timestamp"];?>',
      nonceStr: '<?php echo $signPackage["nonceStr"];?>',
      signature: '<?php echo $signPackage["signature"];?>',
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo'
      ]
    });
    wx.ready(function () {
        //分享给好友
        wx.onMenuShareAppMessage({
            title: "{$content['title']}",
            desc: "{$content['desc']}",
            link: "{$content['link']}",
            imgUrl: "{$content['imgUrl']}",
            success: function (res) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Enroll/addGlod')}",
                    data: {"act_id":act_id},
                    dataType: "json",
                    success: function(data){
                        if(data.state==0){
                            layer.msg('出错了!')
                        }else if(data.state==1){
                            layer.msg('分享成功<br>获得'+data.glod+'金币!');
                        }else if(data.state==2){
                            layer.msg('分享成功<br>重复分享不增加金币!');
                        }
                    }
                }); 
            },
            cancel: function (res) {
                layer.msg('您取消了分享');
            },
            fail: function (res) {
                layer.msg('产生了一个分享错误');
            }
        });
        //分享到朋友圈
        wx.onMenuShareTimeline({
            title: "{$content['title']}",
            desc: "{$content['desc']}",
            link: "{$content['link']}",
            imgUrl: "{$content['imgUrl']}",
            success: function (res) {
                $.ajax({
                    type: "POST",
                    url: "{:U('Enroll/addGlod')}",
                    data: {"act_id":act_id},
                    dataType: "json",
                    success: function(data){
                        if(data.state==0){
                            layer.msg('出错了!')
                        }else if(data.state==1){
                            layer.msg('分享成功<br>获得'+data.glod+'金币!');
                        }else if(data.state==2){
                            layer.msg('分享成功<br>重复分享不增加金币!');
                        }
                    }
                });
            },
            cancel: function (res) {
                layer.msg('您取消了分享');
            },
            fail: function (res) {
                layer.msg('产生了一个分享错误');
            }
        });
    });

    其中像<?php echo $signPackage["appId"];?>这种是由php传递过来的参数

    php端

     /* 加载微信SDK */
            import ( "ORG.Util.ThinkWechat" );
            $weixin = new ThinkWechat ();
            $signPackage = $weixin->GetSignPackage();
            $this->assign('signPackage',$signPackage);
  • 相关阅读:
    Android开发必看知识
    Android 网络通信框架Volley(三)
    Android 网络通信框架Volley(二)
    Android 网络通信框架Volley(一)
    AtomicInteger 一个提供原子操作的Integer类
    Android中px dpi dip density densityDpi 的相关说明
    Android键盘映射
    四十一、Git简介
    四十、git config基本篇
    三十九、git add详解
  • 原文地址:https://www.cnblogs.com/tingfengqieyu/p/5980236.html
Copyright © 2020-2023  润新知