ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1. ~~~ public function config(Request $request){ $url=$request->param( 'url'); $data['appId']='wxa5ed04228937e0fc'; $data['timestamp']=strtotime(date('Y-m-d H:i:s')); $data['nonceStr']=$this->nonceStr(); $data['signature']=$this->signature($data['nonceStr'],$data['timestamp'],$url); return json($data); } ~~~ 2. ~~~ protected function setticket() { $token = $this->gettoken(); $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $token . '&type=jsapi'; $obj = $this->curl_get($url); $data = json_decode($obj, true); $ticket = $data['ticket']; Cache::set('ticket', $ticket, 7000); } ~~~ 3. ~~~ protected function getticket() { $ticket = Cache::get('ticket'); if (empty($ticket)) { $this->setticket(); $ticket = Cache::get('ticket'); } return $ticket; } ~~~ 4. ~~~ protected function signature($noncestr,$timestamp,$url){ $jsapi_ticket = $this->getticket(); $string = 'jsapi_ticket='.$jsapi_ticket.'&noncestr='.$noncestr.'&timestamp='.$timestamp.'&url='.$url; $signature = sha1($string); return $signature; } ~~~ 5. ~~~ protected function nonceStr($length = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'){ if(!is_int($length) || $length < 0){ return false; } $string = ''; for($i = $length; $i > 0; $i--) { $string .= $char[mt_rand(0, strlen($char) - 1)]; } $nonceStr = md5(uniqid(microtime(true),true)); return $nonceStr; } ~~~