美文网首页
微信分享的网络请求及方法

微信分享的网络请求及方法

作者: Mr丶林 | 来源:发表于2017-06-16 16:15 被阅读0次
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    

    前端ajax调用分享接口

        $(function(){
            wx.config({
                debug: false,
                appId: '{$signPackage["appId"]}',
                timestamp: '{$signPackage["timestamp"]}',
                nonceStr: '{$signPackage["nonceStr"]}',
                signature: '{$signPackage["signature"]}',
                jsApiList: [
                    // 所有要调用的 API 都要加到这个列表中
                    'onMenuShareTimeline','onMenuShareAppMessage'
                ]
            });
            wx.ready(function () {
                // 在这里调用 API
                wx.onMenuShareTimeline({
                    title: '{$slogan["title"]}', // 分享标题
                    desc: '{$slogan["desc"]}',//分享描述
                    link: '{$slogan["url"]}', // 分享链接
                    imgUrl: '{$slogan["img"]}', // 分享图标
                    success: successShare,
                });
                wx.onMenuShareAppMessage({
                    title: '{$slogan["title"]}', // 分享标题
                    desc: '{$slogan["desc"]}',//分享描述
                    link: '{$slogan["url"]}', // 分享链接
                    imgUrl: '{$slogan["img"]}',// 分享图标
                    success: successShare,
                });
            });
    
            function successShare () {
                var post_url = '?g=TT&m=Lottery&a=successShare';
                {literal}
                var post_data = {'share':1};
                {/literal}
                //分享成功后 增加抽奖机会
                $.post(post_url,post_data,'json');
                $(".share_nav").fadeOut();
            }
        });
    

    后台接收到ajax请求之后,分享成功,则执行方法

    //成功分享活动  若今日未达到 NUM 次,抽奖机会+1
        public function successShare()
        {
            if (!IS_AJAX) return false;
    
            $actLotteryRecordModel = D('ActLotteryRecord'); //抽奖记录模型
            $actLotteryTicketModel = D('ActLotteryTicket');
    
    
            if ($_REQUEST['share'] == 1) {
                $records = $actLotteryRecordModel->get_lottery_record($this->_user['user_id']);
                if (count($records) < self::NUM) $actLotteryTicketModel->insert($this->_user['user_id'], 2);
            }
    
        }
    

    或者后台设置微信分享后的标题、内容、图标

    //获取微信分享信息
        private function assignShareConf()
        {
            import('@.Com.weixin.jssdk', '', '.php');
            $wx_conf = OpenPlatformConf::weixin_conf();
            $jssdk = new JSSDK($wx_conf['app_id'], $wx_conf['app_secret']);
            $signPackage = $jssdk->GetSignPackage();
    
            $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
            $url = "$protocol$_SERVER[HTTP_HOST]";
    
            $slogan = array(
                'title' => 'Come On!别拦我!我找抽!',
                'desc'  => '你过来,我找抽!百分百中奖,8888元体验金、百万彩票、智能手表等你来!',
                'img'   => $url.'/tpl_dev/TT/weixin/images/Lottery/bgi12.png',
                'url'   => '',
            );
    
            $this->assign(array(
                    'signPackage' => $signPackage,
                    'slogan' => $slogan,
                )
            );
        }
    

    相关文章

      网友评论

          本文标题:微信分享的网络请求及方法

          本文链接:https://www.haomeiwen.com/subject/iklbattx.html