-
- /**
- * @desc APP唤起小程序
- *
- * @author Tao
- * @email 804633234@qq.com
- * @date 2022-09-09 15:19
- * Class ArouseApplet
- */
- class ArouseApplet
- {
- private $appId;
- private $appSecret;
- public function __construct()
- {
- $this->appId=""; //小程序appid
- $this->appSecret="";//小程序密钥
- }
-
- /**
- * @desc 获取凭证
- *
- * @author Tao
- * @email 804633234@qq.com
- * @date 2022-09-09 15:21
- */
- private function getAacessToken():string
- {
- $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appId."&secret=$this->appSecret";
- $data=$this->curl($url,"","GET");
- return $data['access_token'];
- }
-
- /**
- * @desc 获取UrlScheme
- *
- * @author Tao
- * @email 804633234@qq.com
- * @date 2022-09-09 15:28
- */
- public function getUrlScheme():string
- {
- $accessToken=$this->getAacessToken();
- $url="https://api.weixin.qq.com/wxa/generatescheme?access_token=".$accessToken;
- $params=[
- "jump_wxa"=>[
- "path"=> "",
- "query"=> ""
- ]
- ];
- $data=$this->curl($url,json_encode($params));
- return $data['openlink'];
- }
- /**
- * @desc CURL
- *
- * @param $url
- * @param $data
- * @param string $method
- * @return array
- * @author Tao
- * @email 804633234@qq.com
- * @date 2022-09-09 15:27
- */
- private function curl($url,$params,$method="POST"):array
- {
- $reqHeader = array(
- 'Connection: keep-alive',
- 'Content-Type: application/json',
- 'Charset: utf-8'
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, $reqHeader);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- $result = curl_exec($ch);
- return json_decode($result,true);
- }
- }
- ?>