富贵资源网 Design By www.hznty.com
本文实例讲述了thinkphp5框架结合mysql实现微信登录和自定义分享链接与图文功能。分享给大家供大家参考,具体如下:
php代码
function curlHtml($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); //释放curl句柄 curl_close($ch); return $output; } class Wechat { public $errmsg; //微信登录获取用户信息 public function getUserInfo() { //1.准备scope为snsapi_base网页授权页面 $redirect_url = config('system.site_url') . $_SERVER["REQUEST_URI"]; $baseurl = urlencode($redirect_url); $snsapi_base_url = 'https://open.weixin.qq.com/connect/oauth2/authorize"https://api.weixin.qq.com/cgi-bin/user/info".$access_token."&openid=".$openid."&lang=zh_CN"; $content = curlHtml($url); $result = json_decode($content, true); return $result; } /** * [wxShare 微信分享] * @param [type] $url [description] * @return [type] [description] */ public function wxShare() { $noncestr = uniqid(); $timestamp = time(); $url = config('system.site_url') . $_SERVER["REQUEST_URI"]; // $redis = new \Redis; // $ticket_key = 'wx_ticket'; // $ticket = $redis->get($ticket_key); // if (!$ticket) { // $ticket = $this->getJsapiTicket(); // $redis->set($ticket_key, $ticket); // $redis->expire($ticket_key, 7200); // } $ticket = $this->getJsapiTicket(); if ($ticket) { $str = 'jsapi_ticket=' . $ticket . '&noncestr=' . $noncestr . '×tamp=' . $timestamp . '&url=' . $url; $signature = sha1($str); $return_data = [ 'noncestr' => $noncestr, 'timestamp' => $timestamp, 'signature' => $signature, 'appid' => config('system.appid'), 'link' => $url, ]; return $return_data; } } private function getJsapiTicket() { $map['keyname'] = 'Ticket'; $map['modifytime'] = array('GT', time() - 7200); $return = WxTokenModel::getOne('*', $map); if ($return) { return $return['value']; } else { $token_info = $this->curlGetWxAccessToken(); $access_token = $token_info['value']; $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket"htmlcode"><script type="text/javascript" src="/UploadFiles/2021-04-02/jweixin-1.2.0.js">更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...