企业🤖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; } ~~~