Merge remote-tracking branch 'origin/master'
# Conflicts: # wchat/common/HttpClient.php
This commit is contained in:
+15
-15
@@ -17,23 +17,23 @@ use wchat\wx\SmallProgram;
|
|||||||
class Cash_Bonus extends SmallProgram
|
class Cash_Bonus extends SmallProgram
|
||||||
{
|
{
|
||||||
|
|
||||||
public $_cash = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
public string $_cash = '/cgi-bin/hongbao/qpay_hb_mch_send.cgi';
|
||||||
|
|
||||||
private $_errors = [
|
private array $_errors = [
|
||||||
'66228701' => '红包个数超出限制',
|
'66228701' => '红包个数超出限制',
|
||||||
'66228705' => '总金额超出限制',
|
'66228705' => '总金额超出限制',
|
||||||
'66228706' => '总金额不足以按最小金额领取每个红包',
|
'66228706' => '总金额不足以按最小金额领取每个红包',
|
||||||
'66228707' => '商户签名校验失败',
|
'66228707' => '商户签名校验失败',
|
||||||
'66228708' => '重入??',
|
'66228708' => '重入??',
|
||||||
'66228709' => 'openid转换uin失败',
|
'66228709' => 'openid转换uin失败',
|
||||||
'66228711' => '商户订单中的商户号有误',
|
'66228711' => '商户订单中的商户号有误',
|
||||||
'66228712' => '商户订单中的日期超过范围',
|
'66228712' => '商户订单中的日期超过范围',
|
||||||
'66228713' => '余额不足',
|
'66228713' => '余额不足',
|
||||||
'66228715' => '用户未关注公众号,发送AIO消息失败',
|
'66228715' => '用户未关注公众号,发送AIO消息失败',
|
||||||
'66229716' => '用户禁用公众号,发AIO消息失败'
|
'66229716' => '用户禁用公众号,发AIO消息失败'
|
||||||
];
|
];
|
||||||
|
|
||||||
private $_requestParams = [];
|
private array $_requestParams = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
|||||||
+4
-10
@@ -15,19 +15,13 @@ use wchat\common\Result;
|
|||||||
class Account extends SmallProgram
|
class Account extends SmallProgram
|
||||||
{
|
{
|
||||||
|
|
||||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
private string $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||||
private $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
private string $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
||||||
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
private string $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||||
|
|
||||||
private $savePath = __DIR__ . '/../../Users/';
|
private string $savePath = __DIR__ . '/../../Users/';
|
||||||
|
|
||||||
|
|
||||||
private $OK = 0;
|
|
||||||
private $IllegalAesKey = -41001;
|
|
||||||
private $IllegalIv = -41002;
|
|
||||||
private $IllegalBuffer = -41003;
|
|
||||||
private $DecodeBase64Error = -41004;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param $path
|
||||||
*/
|
*/
|
||||||
|
|||||||
+248
-261
@@ -3,312 +3,299 @@
|
|||||||
|
|
||||||
namespace wchat\wx;
|
namespace wchat\wx;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use wchat\common\HttpClient;
|
use wchat\common\HttpClient;
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Message
|
||||||
|
* @package wchat\wx
|
||||||
|
*/
|
||||||
class Message extends SmallProgram
|
class Message extends SmallProgram
|
||||||
{
|
{
|
||||||
const TEXT = 0;
|
|
||||||
const IMAGE = 1;
|
|
||||||
const VOICE = 2;
|
|
||||||
const NEWS = 3;
|
|
||||||
const VIDEO = 4;
|
|
||||||
const MUSIC = 5;
|
|
||||||
const MINIPROGRAMPAGE = 6;
|
|
||||||
const WXCARD = 7;
|
|
||||||
|
|
||||||
private $openid = '';
|
private array $msgData = [];
|
||||||
private $msgData = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $openid
|
* @param string $openid
|
||||||
*/
|
*/
|
||||||
public function setOpenid(string $openid)
|
public function setOpenid(string $openid)
|
||||||
{
|
{
|
||||||
$this->openid = $openid;
|
$this->msgData['touser'] = $openid;
|
||||||
$this->msgData['touser'] = $openid;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendTextNews(string $content)
|
public function sendTextNews(string $content)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'text';
|
$this->msgData['msgtype'] = 'text';
|
||||||
$this->msgData['text[content]'] = $content;
|
$this->msgData['text'] = ['content' => $content];
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
return $this->sendKefuMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $media_id
|
* @param $media_id
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendImageNews(string $media_id)
|
public function sendImageNews(string $media_id)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'image';
|
$this->msgData['msgtype'] = 'image';
|
||||||
$this->msgData['image[media_id]'] = $media_id;
|
$this->msgData['image'] = ['media_id' => $media_id];
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
return $this->sendKefuMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $media_id
|
* @param $media_id
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendVoiceNews(string $media_id)
|
public function sendVoiceNews(string $media_id)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'voice';
|
$this->msgData['msgtype'] = 'voice';
|
||||||
$this->msgData['voice[media_id]'] = $media_id;
|
$this->msgData['voice'] = ['media_id' => $media_id];
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
return $this->sendKefuMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $media_id
|
* @param $media_id
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendMpNewsNews(string $media_id)
|
public function sendMpNewsNews(string $media_id)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'mpnews';
|
$this->msgData['msgtype'] = 'mpnews';
|
||||||
$this->msgData['mpnews[media_id]'] = $media_id;
|
$this->msgData['mpnews'] = ['media_id' => $media_id];
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
return $this->sendKefuMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $picurl
|
* @param string $picurl
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendNewsNews(string $title, string $description, string $url, string $picurl)
|
public function sendNewsNews(string $title, string $description, string $url, string $picurl)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'news';
|
$this->msgData['msgtype'] = 'news';
|
||||||
$this->msgData['news[articles][0][title]'] = $title;
|
$this->msgData['news'] = ['articles' => [[
|
||||||
$this->msgData['news[articles][0][description]'] = $description;
|
'title' => $title,
|
||||||
$this->msgData['news[articles][0][url]'] = $url;
|
'description' => $description,
|
||||||
$this->msgData['news[articles][0][picurl]'] = $picurl;
|
'url' => $url,
|
||||||
|
'picurl' => $picurl
|
||||||
return $this->sendKefuMsg();
|
]]];
|
||||||
}
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendCardNews(string $title)
|
public function sendCardNews(string $title)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'wxcard';
|
$this->msgData['msgtype'] = 'wxcard';
|
||||||
$this->msgData['wxcard[card_id]'] = $title;
|
$this->msgData['wxcard'] = ['card_id' => $title];
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
return $this->sendKefuMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $media_id
|
* @param string $media_id
|
||||||
* @param string $thumb_media_id
|
* @param string $thumb_media_id
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
|
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'video';
|
$this->msgData['msgtype'] = 'video';
|
||||||
$this->msgData['video[media_id]'] = $media_id;
|
$this->msgData['video'] = ['media_id' => [
|
||||||
$this->msgData['video[thumb_media_id]'] = $thumb_media_id;
|
'media_id' => $media_id,
|
||||||
$this->msgData['video[title]'] = $title;
|
'thumb_media_id' => $thumb_media_id,
|
||||||
$this->msgData['video[description]'] = $description;
|
'title' => $title,
|
||||||
|
'description' => $description
|
||||||
return $this->sendKefuMsg();
|
]];
|
||||||
}
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $musicurl
|
* @param string $musicurl
|
||||||
* @param string $hqmusicurl
|
* @param string $hqmusicurl
|
||||||
* @param string $thumb_media_id
|
* @param string $thumb_media_id
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
|
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'music';
|
$this->msgData['msgtype'] = 'music';
|
||||||
$this->msgData['music[title]'] = $title;
|
$this->msgData['music'] = [
|
||||||
$this->msgData['music[description]'] = $description;
|
'title' => $title,
|
||||||
$this->msgData['music[musicurl]'] = $musicurl;
|
'description' => $description,
|
||||||
$this->msgData['music[hqmusicurl]'] = $hqmusicurl;
|
'musicurl' => $musicurl,
|
||||||
$this->msgData['music[thumb_media_id]'] = $thumb_media_id;
|
'hqmusicurl' => $hqmusicurl,
|
||||||
|
'thumb_media_id' => $thumb_media_id
|
||||||
return $this->sendKefuMsg();
|
];
|
||||||
}
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $head_content
|
* @param string $head_content
|
||||||
* @param string $tail_content
|
* @param string $tail_content
|
||||||
* @param array $menus
|
* @param array $menus
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendMenuNews(string $head_content, string $tail_content, array $menus = [])
|
public function sendMenuNews(string $head_content, string $tail_content, array $menus = [])
|
||||||
{
|
{
|
||||||
$this->msgData['msgtype'] = 'msgmenu';
|
$this->msgData['msgtype'] = 'msgmenu';
|
||||||
$this->msgData['msgmenu[head_content]'] = $head_content;
|
$this->msgData['msgmenu'] = [
|
||||||
$this->msgData['msgmenu[tail_content]'] = $tail_content;
|
'head_content' => $head_content,
|
||||||
|
'tail_content' => $tail_content,
|
||||||
|
];
|
||||||
|
if (empty($menus) || !is_array($menus) || count($menus) < 2) {
|
||||||
|
throw new Exception('菜单选项必须有2个');
|
||||||
|
}
|
||||||
|
foreach ($menus as $key => $val) {
|
||||||
|
$this->addNewsMenu($val['id'], $val['name']);
|
||||||
|
}
|
||||||
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($menus) || !is_array($menus) || count($menus) < 2) {
|
private int $index = 0;
|
||||||
throw new \Exception('菜单选项必须有2个');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($menus as $key => $val) {
|
/**
|
||||||
$this->addNewsMenu($val['id'], $val['name']);
|
* @param $id
|
||||||
}
|
* @param $menuName
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addNewsMenu($id, $menuName)
|
||||||
|
{
|
||||||
|
$lists['id'] = $id;
|
||||||
|
$lists['content'] = $menuName;
|
||||||
|
$this->msgData['msgmenu']['list'][$this->index] = $lists;
|
||||||
|
++$this->index;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
/**
|
||||||
}
|
* @param $title
|
||||||
|
* @param $appid
|
||||||
|
* @param $pagepath
|
||||||
|
* @param $thumb_media_id
|
||||||
|
* @return Result
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function sendMiniprogrampageNews(string $title, string $appid, string $pagepath, string $thumb_media_id)
|
||||||
|
{
|
||||||
|
$this->msgData['msgtype'] = 'msgmenu';
|
||||||
|
$this->msgData['miniprogrampage'] = [
|
||||||
|
'title' => $title,
|
||||||
|
'appid' => $appid,
|
||||||
|
'pagepath' => $pagepath,
|
||||||
|
'thumb_media_id' => $thumb_media_id,
|
||||||
|
];
|
||||||
|
return $this->sendKefuMsg();
|
||||||
|
}
|
||||||
|
|
||||||
private $index = 0;
|
/**
|
||||||
|
* @param string $filePath
|
||||||
|
* @param string $type
|
||||||
|
* @param bool $isPermanent
|
||||||
|
* @param string $title
|
||||||
|
* @param string $introduction
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function upload(string $filePath, string $type, $isPermanent = false, string $title = '', string $introduction = '')
|
||||||
|
{
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
throw new Exception('文件不存在');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if (!in_array($type, ['image', 'voice', 'video', 'thumb'])) {
|
||||||
* @param $id
|
throw new Exception('暂不支持的文件类型');
|
||||||
* @param $menuName
|
}
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function addNewsMenu($id, $menuName)
|
|
||||||
{
|
|
||||||
$this->msgData['msgmenu[list][' . $this->index . '][id]'] = $id;
|
|
||||||
$this->msgData['msgmenu[list][' . $this->index . '][content]'] = $menuName;
|
|
||||||
|
|
||||||
++$this->index;
|
$token = $this->getAccessToken();
|
||||||
|
if ($isPermanent) {
|
||||||
|
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$token}&type={$type}";
|
||||||
|
} else {
|
||||||
|
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}";
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
$mime = mime_content_type($filePath);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$real_path = new \CURLFile(realpath($filePath));
|
||||||
* @param $title
|
|
||||||
* @param $appid
|
|
||||||
* @param $pagepath
|
|
||||||
* @param $thumb_media_id
|
|
||||||
* @return Result
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function sendMiniprogrampageNews(string $title, string $appid, string $pagepath, string $thumb_media_id)
|
|
||||||
{
|
|
||||||
$this->msgData['msgtype'] = 'msgmenu';
|
|
||||||
$this->msgData['miniprogrampage[title]'] = $title;
|
|
||||||
$this->msgData['miniprogrampage[appid]'] = $appid;
|
|
||||||
$this->msgData['miniprogrampage[pagepath]'] = $pagepath;
|
|
||||||
$this->msgData['miniprogrampage[thumb_media_id]'] = $thumb_media_id;
|
|
||||||
|
|
||||||
return $this->sendKefuMsg();
|
$data = array("media" => $real_path, 'form-data[filename]' => $filePath, 'form-data[Content-Type]' => $mime);
|
||||||
}
|
if ($isPermanent && $mime == 'video/mp3') {
|
||||||
|
$data = ['media' => $real_path, 'description[title]' => $title, 'description[introduction]' => $introduction];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
$this->request->setMethod(HttpClient::POST);
|
||||||
* @param string $filePath
|
|
||||||
* @param string $type
|
|
||||||
* @param bool $isPermanent
|
|
||||||
* @param string $title
|
|
||||||
* @param string $introduction
|
|
||||||
* @return mixed
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function upload(string $filePath, string $type, $isPermanent = false, string $title = '', string $introduction = '')
|
|
||||||
{
|
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
throw new \Exception('文件不存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($type, ['image', 'voice', 'video', 'thumb'])) {
|
/** @var Result $body */
|
||||||
throw new \Exception('暂不支持的文件类型');
|
$data = $this->request->post($url, $data);
|
||||||
}
|
if (!$data->isResultsOK()) {
|
||||||
|
throw new Exception($data->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$token = $this->getAccessToken();
|
return $data->getData();
|
||||||
if ($isPermanent) {
|
}
|
||||||
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$token}&type={$type}";
|
|
||||||
} else {
|
|
||||||
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}";
|
|
||||||
}
|
|
||||||
|
|
||||||
$mime = mime_content_type($filePath);
|
|
||||||
|
|
||||||
$real_path = new \CURLFile(realpath($filePath));
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getContents()
|
||||||
|
{
|
||||||
|
return $this->msgData;
|
||||||
|
}
|
||||||
|
|
||||||
$data = array("media" => $real_path, 'form-data[filename]' => $filePath, 'form-data[Content-Type]' => $mime);
|
|
||||||
if ($isPermanent && $mime == 'video/mp3') {
|
|
||||||
$data = ['media' => $real_path, 'description[title]' => $title, 'description[introduction]' => $introduction];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->request->setMethod(HttpClient::POST);
|
/**
|
||||||
|
* @return Result
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function sendKefuMsg()
|
||||||
|
{
|
||||||
|
$data = json_encode($this->msgData, JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
/** @var Result $body */
|
$url = '/cgi-bin/message/custom/send?access_token=' . $this->getAccessToken();
|
||||||
$data = $this->request->post($url, $data);
|
$this->request->setMethod(HttpClient::POST);
|
||||||
if (!$data->isResultsOK()) {
|
$this->request->setErrorField('errcode');
|
||||||
throw new \Exception($data->getMessage());
|
$this->request->setErrorMsgField('errmsg');
|
||||||
}
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
|
||||||
return $data->getData();
|
$this->request->addHeader('Content-Type', 'application/json');
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** @var Result $body */
|
||||||
* @param $mime
|
$body = $this->request->post($url, $data);
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
private function checkExtinfo($mime)
|
|
||||||
{
|
|
||||||
switch (strtolower($mime)) {
|
|
||||||
case 'image/bmp':
|
|
||||||
case 'image/png':
|
|
||||||
case 'image/jpeg':
|
|
||||||
case 'image/jpg':
|
|
||||||
case 'image/gif':
|
|
||||||
break;
|
|
||||||
case 'mp3/wma/wav/amr':
|
|
||||||
break;
|
|
||||||
case 'mp4';
|
|
||||||
break;
|
|
||||||
case 'jpg';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new \Exception('不支持的文件格式');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (!$body->isResultsOK()) {
|
||||||
* @param $data
|
throw new Exception($body->getMessage());
|
||||||
* @return Result
|
}
|
||||||
* @throws \Exception
|
return $body;
|
||||||
*/
|
}
|
||||||
private function sendKefuMsg()
|
|
||||||
{
|
|
||||||
$data = json_encode($this->msgData, JSON_UNESCAPED_UNICODE);
|
|
||||||
|
|
||||||
$url = '/cgi-bin/message/custom/send?access_token=' . $this->getAccessToken();
|
|
||||||
$this->request->setMethod(HttpClient::POST);
|
|
||||||
$this->request->setErrorField('errcode');
|
|
||||||
$this->request->setErrorMsgField('errmsg');
|
|
||||||
|
|
||||||
/** @var Result $body */
|
|
||||||
$body = $this->request->post($url, $data);
|
|
||||||
|
|
||||||
if (!$body->isResultsOK()) {
|
|
||||||
throw new \Exception($body->getMessage());
|
|
||||||
}
|
|
||||||
return $body;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ use wchat\common\Help;
|
|||||||
*/
|
*/
|
||||||
class Recharge extends SmallProgram
|
class Recharge extends SmallProgram
|
||||||
{
|
{
|
||||||
private $money = 0;
|
private int $money = 0;
|
||||||
|
|
||||||
private $orderNo;
|
private $orderNo;
|
||||||
|
|
||||||
private $data = [];
|
private array $data = [];
|
||||||
|
|
||||||
private $transfers = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
private string $transfers = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
||||||
private $uniformed = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
|
private string $uniformed = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $money
|
* @param int $money
|
||||||
|
|||||||
+18
-7
@@ -13,11 +13,11 @@ use wchat\common\Result;
|
|||||||
class SecCheck extends SmallProgram
|
class SecCheck extends SmallProgram
|
||||||
{
|
{
|
||||||
|
|
||||||
private $_url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=';
|
private string $_url = '/wxa/img_sec_check?access_token=';
|
||||||
|
|
||||||
private $_msgUrl = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=';
|
private string $_msgUrl = '/wxa/msg_sec_check?access_token=';
|
||||||
|
|
||||||
private $_mediaCheckAsync = 'https://api.weixin.qq.com/wxa/media_check_async?access_token=';
|
private string $_mediaCheckAsync = '/wxa/media_check_async?access_token=';
|
||||||
|
|
||||||
const MEDIA_VIDEO = 1;
|
const MEDIA_VIDEO = 1;
|
||||||
const MEDIA_IMAGE = 1;
|
const MEDIA_IMAGE = 1;
|
||||||
@@ -32,6 +32,8 @@ class SecCheck extends SmallProgram
|
|||||||
return $this->sendError('文件不存在', 404);
|
return $this->sendError('文件不存在', 404);
|
||||||
}
|
}
|
||||||
$this->request->setUseSwoole(false);
|
$this->request->setUseSwoole(false);
|
||||||
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
$this->request->setHeader('Content-Type', 'multipart/form-data');
|
$this->request->setHeader('Content-Type', 'multipart/form-data');
|
||||||
$this->request->setErrorField('errcode');
|
$this->request->setErrorField('errcode');
|
||||||
$this->request->setErrorMsgField('errmsg');
|
$this->request->setErrorMsgField('errmsg');
|
||||||
@@ -50,10 +52,14 @@ class SecCheck extends SmallProgram
|
|||||||
if (!in_array($type, [self::MEDIA_IMAGE, self::MEDIA_VIDEO])) {
|
if (!in_array($type, [self::MEDIA_IMAGE, self::MEDIA_VIDEO])) {
|
||||||
throw new \Exception('暂不支持的文件类型');
|
throw new \Exception('暂不支持的文件类型');
|
||||||
}
|
}
|
||||||
$this->request->setHeader('Content-Type', 'application/json');
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setHeader('Content-Type', 'application/json');
|
||||||
$this->request->setErrorField('errcode');
|
$this->request->setErrorField('errcode');
|
||||||
$this->request->setErrorMsgField('errmsg');
|
$this->request->setErrorMsgField('errmsg');
|
||||||
$response = $this->request->post($this->_mediaCheckAsync . $this->config->getAccessToken(), [
|
|
||||||
|
$requestUrl = $this->_mediaCheckAsync . $this->config->getAccessToken();
|
||||||
|
$response = $this->request->post($requestUrl, [
|
||||||
'media_url' => $url,
|
'media_url' => $url,
|
||||||
'media_type' => $type
|
'media_type' => $type
|
||||||
]);
|
]);
|
||||||
@@ -83,10 +89,15 @@ class SecCheck extends SmallProgram
|
|||||||
if (empty($content)) {
|
if (empty($content)) {
|
||||||
return $this->sendError('文件不存在', 404);
|
return $this->sendError('文件不存在', 404);
|
||||||
}
|
}
|
||||||
$this->request->setHeader('Content-Type', 'application/json');
|
$this->request->setIsSSL(true);
|
||||||
|
$this->request->setHost('api.weixin.qq.com');
|
||||||
|
$this->request->setHeader('Content-Type', 'application/json');
|
||||||
$this->request->setErrorField('errcode');
|
$this->request->setErrorField('errcode');
|
||||||
$this->request->setErrorMsgField('errmsg');
|
$this->request->setErrorMsgField('errmsg');
|
||||||
return $this->request->post($this->_msgUrl . $this->config->getAccessToken(), ['content' => $content]);
|
|
||||||
|
$requestUrl = $this->_msgUrl . $this->config->getAccessToken();
|
||||||
|
|
||||||
|
return $this->request->post($requestUrl, ['content' => $content]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ class SmallProgram extends Miniprogarampage
|
|||||||
private $url = 'https://api.weixin.qq.com/cgi-bin/token';
|
private $url = 'https://api.weixin.qq.com/cgi-bin/token';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param bool $get_token
|
||||||
* @throws \Exception
|
* @return mixed
|
||||||
*/
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function generateAccess_token($get_token = false)
|
public function generateAccess_token($get_token = false)
|
||||||
{
|
{
|
||||||
if (!empty($this->config->getToken())) {
|
if (!empty($this->config->getToken())) {
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ namespace wchat\wx;
|
|||||||
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Subject
|
||||||
|
* @package wchat\wx
|
||||||
|
*/
|
||||||
class Subject extends \wchat\base\Subject
|
class Subject extends \wchat\base\Subject
|
||||||
{
|
{
|
||||||
|
|
||||||
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send';
|
private string $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace wchat\wx;
|
|||||||
*/
|
*/
|
||||||
class Template extends \wchat\base\Template
|
class Template extends \wchat\base\Template
|
||||||
{
|
{
|
||||||
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send';
|
private string $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send';
|
||||||
|
|
||||||
public function getUrl(): string
|
public function getUrl(): string
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user