| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace app\extra\weMini;
- use yzh52521\EasyHttp\Http;
- class Link extends BasicWeChat
- {
- public function createQrcodeWx(string $path = "",string $query = "", string $filePath = "")
- {
- $url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={$this->getAccessToken()}";
- $data = [
- "path" => $path."?".$query,
- 'width' => 430
- ];
- // 初始化cURL
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // 执行请求
- $response = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- // 检查请求是否成功
- if ($httpCode != 200) {
- return false;
- }
- // 检查返回的是否是JSON(错误情况)
- $decode = json_decode($response, true);
- if ($decode && isset($decode['errcode'])) {
- error_log("微信接口返回错误: " . $decode['errmsg']);
- return false;
- }
- // 保存为JPG文件
- $filePath = public_path().$filePath;
- $result = file_put_contents($filePath, $response);
- if ($result === false) {
- error_log("文件保存失败: " . $filePath);
- return false;
- }
- return $filePath;
- // echo $url;
- // print_r($param);
- // return Http::asJson()->post($url,$param);
- }
- public function createQrcode(string $path = "",string $query = "", string $filePath = "")
- {
- $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$this->getAccessToken()}";
- $data = [
- "path" => $path."?".$query,
- 'width' => 430
- ];
- // 初始化cURL
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // 执行请求
- $response = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- // 检查请求是否成功
- if ($httpCode != 200) {
- return false;
- }
- // 检查返回的是否是JSON(错误情况)
- $decode = json_decode($response, true);
- if ($decode && isset($decode['errcode'])) {
- error_log("微信接口返回错误: " . $decode['errmsg']);
- return false;
- }
- // 保存为JPG文件
- $filePath = public_path().$filePath;
- $result = file_put_contents($filePath, $response);
- if ($result === false) {
- error_log("文件保存失败: " . $filePath);
- return false;
- }
- return $filePath;
- // echo $url;
- // print_r($param);
- // return Http::asJson()->post($url,$param);
- }
- public function createLink(string $path = "",string $query = "",string $version = "release")
- {
- $url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token={$this->getAccessToken()}";
- $param = [
- "path" => $path,
- "query" => $query,
- "env_version" => $version
- ];
- return Http::asJson()->post($url,$param)->array();
- }
- public function createLinkJump(string $path = "",string $query = "",string $version = "release")
- {
- $url = "https://api.weixin.qq.com/wxa/generatescheme?access_token={$this->getAccessToken()}";
- $param = [
- "jump_wxa" => [
- "path" => $path,
- "query" => $query,
- "env_version" => $version
- ],
- ];
- print_r($param);
- return Http::asJson()->post($url,$param)->array();
- }
- public function createShortLink(string $path = "",string $query = "",string $version = "release")
- {
- $url = "https://api.weixin.qq.com/wxa/genwxashortlink?access_token={$this->getAccessToken()}";
- $param = [
- "page_url" => $path."?".$query,
- ];
- return Http::asJson()->post($url,$param)->array();
- }
- }
|