• 公众号开发【分享功能】


    分享功能代码如下:

    关联页面share.html

    //获取JsApiTicket票据的方法
         function getJsApiTicket(){
           //如果session中保存
           if($_SESSION['jsapi_ticket_expire_time']>time() && $_SESSION['jsapi_ticket']){
             $jsapi_ticket=$_SESSION['jsapi_ticket'];
           }else{
             //$access_token=$this->getWxAccessToken();因为获取失败 不好用 所以测试账号获得
             $access_token="12_EDjuJXo7AKFzpxOWcgis-F_EaXNT6ITQt6ZBbMgMUhuqySF-5aD5bUv-p1TPT63oTIy3uXSDVMDIbnrcpzdFXgfqxHGZbN2_-lzlZ8MKUQ3dskH3B7wpkr1aQymY459MjXYfioZJJW7FNYnLYMNjAHAIWX";
             $url="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
             $res=$this->http_curl($url);
             $jsapi_ticket=$res['ticket'];
             $_SESSION['jsapi_ticket']=$jsapi_ticket;
             $_SESSION['jsapi_ticket_expire_time']=time()+7000;
           }
           return $jsapi_ticket;
         }//getJsApiTicket end
       //获取noncestr随机码
       function getRandCode($num=16){
            $array=array(
              'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
              'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
              '0','1','2','3','4','5','6','7','8','9'
            );
            $tmpstr='';
            $max=count($array);
            for($i=1;$i<=$num;$i++){
              $key=rand(0,$max-1);
              $tmpstr.=$array[$key];
            }
            return $tmpstr;


       } //getRandCode end
        //微信分享
         function shareWx(){
           //1.获取jsapi_ticket票据
           $jsapi_ticket=$this->getJsApiTicket();
           $timestamp=time();
           $noncestr=$this->getRandCode();
           $url='http://l1230205.applinzi.com/gzh/wx.php/Index/shareWx';
           //2.获取signature
           $signature="jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."&timestamp=".$timestamp."&url=".$url;
           $signature=sha1($signature);
           $this->assign('name','imooc');
           $this->assign('timestamp',$timestamp);
           $this->assign('noncestr',$noncestr);
           $this->assign('signature',$signature);
           $this->display('share');
         }//shareWx end

  • 相关阅读:
    【数据库】Navicat Premium12远程连接MySQL数据库
    【Linux】一步一步学Linux——Centos7.5安装图解(08)
    【Tools】VMware虚拟机三种网络模式详解和操作
    【Linux】一步一步学Linux——VMware虚拟机三种网络模式详解(07)
    【Linux】一步一步学Linux——VMware Workstation 15 Pro安装图解教程(06)
    微信公众平台开发(25) 数据库操作
    微信公众平台开发(24) 自定义菜单功能开发
    微信公众平台开发(23) 聊天机器人功能开发
    微信公众平台开发(22) 翻译功能开发
    微信公众平台开发(21) 天气预报功能开发
  • 原文地址:https://www.cnblogs.com/lxj0205/p/9396323.html
Copyright © 2020-2023  润新知