From a83b65e7f2e05200efd010bc308490d0f300879d Mon Sep 17 00:00:00 2001 From: fanbo <3412853751@qq.com> Date: Mon, 23 Dec 2024 21:14:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BB=A5=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=BD=AF=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- accesstoken.lib.php | 69 ---- advancedbroadcast.lib.php | 400 -------------------- auth.lib.php | 21 - autoreply.lib.php => core/autoreply.lib.php | 3 +- core/curl.lib.php | 137 +++++++ core/customservice.lib.php | 65 ++++ core/intelligentinterface.lib.php | 20 + core/media.lib.php | 46 ++- core/templatemessage.lib.php | 36 ++ core/usermanage.lib.php | 66 ++++ popularize.lib.php | 78 ---- 11 files changed, 371 insertions(+), 570 deletions(-) delete mode 100644 accesstoken.lib.php delete mode 100644 advancedbroadcast.lib.php delete mode 100644 auth.lib.php rename autoreply.lib.php => core/autoreply.lib.php (87%) create mode 100644 core/curl.lib.php create mode 100644 core/customservice.lib.php create mode 100644 core/intelligentinterface.lib.php create mode 100644 core/templatemessage.lib.php create mode 100644 core/usermanage.lib.php delete mode 100644 popularize.lib.php diff --git a/accesstoken.lib.php b/accesstoken.lib.php deleted file mode 100644 index 51e266d..0000000 --- a/accesstoken.lib.php +++ /dev/null @@ -1,69 +0,0 @@ - \ No newline at end of file diff --git a/advancedbroadcast.lib.php b/advancedbroadcast.lib.php deleted file mode 100644 index 8a7d354..0000000 --- a/advancedbroadcast.lib.php +++ /dev/null @@ -1,400 +0,0 @@ -'多媒体ID,由多媒体上传接口获得' , 'author'=>'作者', 'title'=>'标题', 'content_source_url'=>'www.lanecn.com', content=>'图文消息页面的内容,支持HTML标签', 'digest'=>'摘要', 'show_cover_pic'=>'是否设置为封面(0或者1)'), - array('thumb_media_id'=>'多媒体ID,由多媒体上传接口获得' , 'author'=>'作者', 'title'=>'标题', 'content_source_url'=>'www.lanecn.com', content=>'图文消息页面的内容,支持HTML标签', 'digest'=>'摘要', 'show_cover_pic'=>'是否设置为封面(0或者1)'), - * ) - * - * return mediaId 上传的图文消息的ID - */ - public static function uploadNews($articles){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - foreach($articles as &$article){ - $article['author'] = urlencode($article['author']); - $article['title'] = urlencode($article['title']); - $article['content'] = urlencode($article['content']); - $article['digest'] = urlencode($article['digest']); - } - $template = array(); - $template['articles'] = $articles; - $template = json_encode($template); - $template = urldecode($template); - $result = Curl::callWebServer($queryUrl, $template, $queryAction); - return empty($result['media_id']) ? false : $result['media_id']; - } - - /** - * 根据分组进行群发 - 发送图文消息 - * - * @param $groupId Int 要发送的分组ID - * @param $mediaId String 必须通过self::uploadNews获得的多媒体资源ID - * @param $isToAll Bool 使用is_to_all为true且成功群发,会使得此次群发进入历史消息列表。 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentNewsByGroup($groupId, $mediaId, $isToAll=false){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['filter']['group_id'] = $groupId; - $template['filter']['is_to_all'] = $isToAll; - $template['mpnews']['media_id'] = $mediaId; - $template['msgtype'] = 'mpnews'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据分组进行群发 - 发送文本消息 - * - * @param $groupId 要发送的分组ID - * @param $content 文本消息的内容 - * @param $isToAll Bool 使用is_to_all为true且成功群发,会使得此次群发进入历史消息列表。 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentTextByGroup($groupId, $content, $isToAll=false){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['filter']['group_id'] = $groupId; - $template['filter']['is_to_all'] = $isToAll; - $template['text']['content'] = $content; - $template['msgtype'] = 'text'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据分组进行群发 - 发送语音消息 - * - * @param $groupId 要发送的分组ID - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @param $isToAll Bool 使用is_to_all为true且成功群发,会使得此次群发进入历史消息列表。 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentVoiceByGroup($groupId, $mediaId, $isToAll=false){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['filter']['group_id'] = $groupId; - $template['filter']['is_to_all'] = $isToAll; - $template['voice']['media_id'] = $mediaId; - $template['msgtype'] = 'voice'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据分组进行群发 - 发送图片消息 - * - * @param $groupId 要发送的分组ID - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @param $isToAll Bool 使用is_to_all为true且成功群发,会使得此次群发进入历史消息列表。 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentImageByGroup($groupId, $mediaId, $isToAll=false){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['filter']['group_id'] = $groupId; - $template['filter']['is_to_all'] = $isToAll; - $template['image']['media_id'] = $mediaId; - $template['msgtype'] = 'image'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据分组进行群发 - 发送视频消息 - * - * @param $groupId 要发送的分组ID - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @param $isToAll Bool 使用is_to_all为true且成功群发,会使得此次群发进入历史消息列表。 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentVideoByGroup($mediaId, $title, $description, $groupId, $isToAll=false){ - //将根据基础支持中上传多媒体得到的mediaId转化为群发视频消息所需要的mediaId。 - $queryUrl = 'https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['media_id'] = $mediaId; - $template['title'] = $title; - $template['description'] = $description; - $template = json_encode($template); - $result = Curl::callWebServer($queryUrl, $template, $queryAction); - if(empty($result['type']) || $result['type'] != 'video' || empty($result['media_id'])){ - return $result; - } - $mediaId = $result['media_id']; - //群发视频 - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['filter']['group_id'] = $groupId; - $template['filter']['is_to_all'] = $isToAll; - $template['mpvideo']['media_id'] = $mediaId; - $template['msgtype'] = 'mpvideo'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据OpenID列表群发 - 发送图文消息 - * - * @param $toUserList array(openId1, openId2, openId3) - * @param $mediaId String 必须通过self::uploadNews获得的多媒体资源ID - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentNewsByOpenId($toUserList, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $toUserList; - $template['mpnews']['media_id'] = $mediaId; - $template['msgtype'] = 'mpnews'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据OpenID列表群发 - 发送文本消息 - * - * @param $toUserList array(openId1, openId2, openId3) - * @param $content 文本消息的内容 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentTextByOpenId($toUserList, $content){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $toUserList; - $template['text']['content'] = $content; - $template['msgtype'] = 'text'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据OpenID列表群发 - 发送语音消息 - * - * @param $toUserList array(openId1, openId2, openId3) - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentVoiceByOpenId($toUserList, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $toUserList; - $template['voice']['media_id'] = $mediaId; - $template['msgtype'] = 'voice'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据OpenID列表群发 - 发送图片消息 - * - * @param $toUserList array(openId1, openId2, openId3) - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentImageByOpenId($toUserList, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $toUserList; - $template['image']['media_id'] = $mediaId; - $template['msgtype'] = 'image'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 根据OpenID列表群发 - 发送视频消息 - * - * @param $toUserList array(openId1, openId2, openId3) - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function sentVideoByOpenId($toUserList, $mediaId, $title, $description){ - //将根据基础支持中上传多媒体得到的mediaId转化为群发视频消息所需要的mediaId。 - $queryUrl = 'https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['media_id'] = $mediaId; - $template['title'] = $title; - $template['description'] = $description; - $template = json_encode($template); - $result = Curl::callWebServer($queryUrl, $template, $queryAction); - if(empty($result['type']) || $result['type'] != 'video' || empty($result['media_id'])){ - return $result; - } - $mediaId = $result['media_id']; - //群发视频 - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $toUserList; - $template['video']['media_id'] = $mediaId; - $template['video']['title'] = $title; - $template['video']['description'] = $description; - $template['msgtype'] = 'video'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 删除群发 - * 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片。 另外,删除群发消息只能删除图文消息和视频消息,其他类型的消息一经发送,无法删除。 - * - * @param $msgId 发送出去的消息ID - * @return mixed array("errcode"=>0, "errmsg"=>"ok"} 正常是errcode为0 - */ - public static function delete($msgId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['msg_id'] = $msgId; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - - - - - /** - * 预览 - 预览图文消息 - * - * @param $openId String 发送消息给指定用户,该用户的OpenId - * @param $mediaId String 必须通过self::uploadNews获得的多媒体资源ID - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function previewNewsByGroup($openId, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['mpnews']['media_id'] = $mediaId; - $template['msgtype'] = 'mpnews'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 预览 - 预览文本消息 - * - * @param $openId String 发送消息给指定用户,该用户的OpenId - * @param $content 文本消息的内容 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function previewTextByGroup($openId, $content){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['text']['content'] = $content; - $template['msgtype'] = 'text'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 预览 - 预览语音消息 - * - * @param $openId String 发送消息给指定用户,该用户的OpenId - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function previewVoiceByGroup($openId, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['voice']['media_id'] = $mediaId; - $template['msgtype'] = 'voice'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 预览 - 预览图片消息 - * - * @param $openId String 发送消息给指定用户,该用户的OpenId - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function previewImageByGroup($openId, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['image']['media_id'] = $mediaId; - $template['msgtype'] = 'image'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 预览 - 预览视频消息 - * - * @param $openId String 发送消息给指定用户,该用户的OpenId - * @param $mediaId 需通过基础支持中的上传下载多媒体文件来得到。Media::upload()中返回的media_id字段的值 - * @return mixed array("errcode"=>0, "errmsg"=>"success","msg_id"=>34182} 正常是errcode为0 - */ - public static function previewVideoByGroup($mediaId, $title, $description, $openId){ - //将根据基础支持中上传多媒体得到的mediaId转化为群发视频消息所需要的mediaId。 - $queryUrl = 'https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['media_id'] = $mediaId; - $template['title'] = $title; - $template['description'] = $description; - $template = json_encode($template); - $result = Curl::callWebServer($queryUrl, $template, $queryAction); - if(empty($result['type']) || $result['type'] != 'video' || empty($result['media_id'])){ - return $result; - } - $mediaId = $result['media_id']; - //群发视频 - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['mpvideo']['media_id'] = $mediaId; - $template['msgtype'] = 'mpvideo'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 查询群发消息发送状态【订阅号与服务号认证后均可用】 - * - * @param $msgId String 群发消息后返回的消息id - * @return mixed array("msg_status":"SEND_SUCCESS","msg_id"=>34182) - */ - public static function getStatus($openId, $mediaId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/mass/get?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['touser'] = $openId; - $template['image']['media_id'] = $mediaId; - $template['msgtype'] = 'image'; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } -} \ No newline at end of file diff --git a/auth.lib.php b/auth.lib.php deleted file mode 100644 index 2b2fb32..0000000 --- a/auth.lib.php +++ /dev/null @@ -1,21 +0,0 @@ - $val) { + if($is_urlcode){ + $encode_key = urlencode($key); + }else{ + $encode_key = $key; + } + if ($encode_key != $key) { + unset($query[$key]); + } + if($is_urlcode){ + $query[$encode_key] = urlencode($val); + }else{ + $query[$encode_key] = $val; + } + } + } + curl_setopt(self::$_ch, CURLOPT_URL, $url); + curl_setopt(self::$_ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt(self::$_ch, CURLOPT_HEADER, 0); + curl_setopt(self::$_ch, CURLOPT_POST, true ); + curl_setopt(self::$_ch, CURLOPT_POSTFIELDS, $query); + curl_setopt(self::$_ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt(self::$_ch, CURLOPT_SSL_VERIFYHOST, FALSE); + curl_setopt(self::$_ch, CURLOPT_SSLVERSION, 1); + + $ret = self::_execute(); + self::_close(); + return $ret; + } + + private static function _put($url, $query = array()) { + curl_setopt(self::$_ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + + return self::_httpPost($url, $query); + } + + private static function _delete($url, $query = array()) { + curl_setopt(self::$_ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + + return self::_httpPost($url, $query); + } + + private static function _head($url, $query = array()) { + curl_setopt(self::$_ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); + + return self::_httpPost($url, $query); + } + + private static function _execute() { + $response = curl_exec(self::$_ch); + $errno = curl_errno(self::$_ch); + + if ($errno > 0) { + throw new \Exception(curl_error(self::$_ch), $errno); + } + return $response; + } +} + +?> \ No newline at end of file diff --git a/core/customservice.lib.php b/core/customservice.lib.php new file mode 100644 index 0000000..ac7334c --- /dev/null +++ b/core/customservice.lib.php @@ -0,0 +1,65 @@ + '@' . $filename); + // 发起POST请求,上传文件 return Curl::callWebServer($queryUrl, $data, 'POST', 1, 0); } + + /** + * 从微信服务器下载多媒体文件 + * 此方法根据提供的media_id从微信服务器下载对应的多媒体文件。 + * + * @param string $mediaId 微信服务器上的多媒体文件ID + * @return mixed 下载的文件内容或下载失败的错误信息 + * + * 下载多媒体文件时的HTTP头信息示例: + * HTTP/1.1 200 OK + * Connection: close + * Content-Type: image/jpeg + * Content-disposition: attachment; filename="MEDIA_ID.jpg" + * Date: Sun, 06 Jan 2013 10:20:18 GMT + * Cache-Control: no-cache, must-revalidate + * Content-Length: 339721 + * + * 使用curl命令下载多媒体文件的示例: + * curl -G "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID" + */ public static function download($mediaId) { + // 获取微信公众号的ACCESS_TOKEN $accessToken = AccessToken::getAccessToken(); + // 构造多媒体文件下载的URL $queryUrl = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $accessToken . '&media_id=' . $mediaId; + // 发起GET请求,下载文件 return Curl::callWebServer($queryUrl, '', 'GET', 0); } } \ No newline at end of file diff --git a/core/templatemessage.lib.php b/core/templatemessage.lib.php new file mode 100644 index 0000000..7d70e4b --- /dev/null +++ b/core/templatemessage.lib.php @@ -0,0 +1,36 @@ +$openId, 'remark'=>$remark)); + return Curl::callWebServer($queryUrl, $data, 'POST'); + } + + public static function getNetworkState(){ + echo "WeixinJSBridge.invoke('getNetworkType',{},function(e){WeixinJSBridge.log(e.err_msg);});"; + } +} \ No newline at end of file diff --git a/popularize.lib.php b/popularize.lib.php deleted file mode 100644 index b7d4297..0000000 --- a/popularize.lib.php +++ /dev/null @@ -1,78 +0,0 @@ -"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==", - * //二维码的有效时间,以秒为单位。最大不超过1800。 - * "expire_seconds"=>60, - * //二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片 - * "url"=>"http://weixin.qq.com/q/kZgfwMTm72WWPkovabbI" - * ) - */ - public static function createTicket($type, $expireSeconds, $sceneId){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - if($type == 1){ - $template['expire_seconds'] = $expireSeconds; - $template['action_name'] = 'QR_SCENE'; - }else{ - $template['action_name'] = 'QR_LIMIT_SCENE'; - } - $template['action_info']['scene']['scene_id'] = $sceneId; - $template = json_encode($template); - return Curl::callWebServer($queryUrl, $template, $queryAction); - } - - /** - * 生成带参数的二维码 - 第二步 通过ticket换取二维码 - * @param $ticket Popularize::createTicket()获得的 - * @param $filename String 文件路径,如果不为空,则会创建一个图片文件,二维码文件为jpg格式,保存到指定的路径 - * @return 直接echo本函数的返回值,并在调用页面添加header('Content-type: image/jpg');,将会展示出一个二维码的图片。 - */ - public static function getQrcode($ticket, $filename=''){ - $queryUrl = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode($ticket); - $queryAction = 'GET'; - $result = Curl::callWebServer($queryUrl, '', $queryAction, 0); - if(!empty($filename)){ - file_put_contents($filename, $result); - } - return $result; - } - - /** - * 将一条长链接转成短链接。 - * 主要使用场景:开发者用于生成二维码的原链接(商品、支付二维码等)太长导致扫码速度和成功率下降,将原长链接通过此接口转成短链接再生成二维码将大大提升扫码速度和成功率。 - * @param $longUrl String 需要转换的长链接,支持http://、https://、weixin://wxpay 格式的url - * @return array('errcode'=>0, 'errmsg'=>'错误信息', 'short_url'=>'http://t.cn/asdasd')错误码为0表示正常 - */ - public static function long2short($longUrl){ - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token='.AccessToken::getAccessToken(); - $queryAction = 'POST'; - $template = array(); - $template['long_url'] = $longUrl; - $template['action'] = 'long2short'; - return Curl::callWebServer($queryUrl, '', $queryAction); - } -} \ No newline at end of file