From 432c9eb8f49c230b7ebadd9ea3f67291e211101c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 21 Sep 2020 13:51:40 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E7=9B=B4=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 + src/common.php | 2 +- src/service/decent/EJiAoFei.php | 2 +- src/service/qiniu/SmsService.php | 394 +++++++++++++++++++++++++++++ src/service/wechat/MiniService.php | 225 ++++++++++++++++ 5 files changed, 624 insertions(+), 2 deletions(-) create mode 100644 src/service/qiniu/SmsService.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 11d084b..bba6bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.115 / 2020-09-21 +- 微信小程序接口增加直播 + ## v6.0.114 / 2020-09-16 - 优化鼎信缴费平台充值接口 diff --git a/src/common.php b/src/common.php index 44ffa18..bf39ecd 100644 --- a/src/common.php +++ b/src/common.php @@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; /** * 定义当前版本 */ -const VERSION = '6.0.114'; +const VERSION = '6.0.115'; if (!function_exists('get_ip_info')) { /** diff --git a/src/service/decent/EJiAoFei.php b/src/service/decent/EJiAoFei.php index 7242ab4..8f5df95 100644 --- a/src/service/decent/EJiAoFei.php +++ b/src/service/decent/EJiAoFei.php @@ -161,7 +161,7 @@ class EJiAoFei extends Service */ public function gprsChongzhiAdvance(string $orderid, string $account, int $gprs, int $area, int $effecttime, int $validity, string $times): self { - $this->method = 'queryTXproduct'; + $this->method = 'gprsChongzhiAdvance'; $this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&gprs={$gprs}&area={$area}&effecttime={$effecttime}&validity={$validity}×={$times}"; return $this; } diff --git a/src/service/qiniu/SmsService.php b/src/service/qiniu/SmsService.php new file mode 100644 index 0000000..959aedd --- /dev/null +++ b/src/service/qiniu/SmsService.php @@ -0,0 +1,394 @@ +accessKey = $accessKey; + return $this; + } + + /** + * @param string $secretKey + * @return $this + */ + public function secretKey(string $secretKey): self + { + $this->secretKey = $secretKey; + return $this; + } + + /** + * 请求参数 + * @param array $param + * @return $this + */ + public function param(array $param): self + { + $this->param = $param; + return $this; + } + + /** + * 发送短信 + * https://developer.qiniu.com/sms/api/5897/sms-api-send-message#1 + * @return $this + */ + public function message(): self + { + $this->url = "https://sms.qiniuapi.com/v1/message"; + $this->method = "POST"; + return $this; + } + + /** + * 发送单条短信 + * https://developer.qiniu.com/sms/api/5897/sms-api-send-message#2 + * @return $this + */ + public function messageSingle(): self + { + $this->url = "https://sms.qiniuapi.com/v1/message/single"; + $this->method = "POST"; + return $this; + } + + /** + * 发送国际/港澳台短信 + * https://developer.qiniu.com/sms/api/5897/sms-api-send-message#3 + * @return $this + */ + public function messageOversea(): self + { + $this->url = "https://sms.qiniuapi.com/v1/message/oversea"; + $this->method = "POST"; + return $this; + } + + /** + * 发送全文本短信(不需要传模版 ID) + * https://developer.qiniu.com/sms/api/5897/sms-api-send-message#3 + * @return $this + */ + public function messageFulltext(): self + { + $this->url = "https://sms.qiniuapi.com/v1/message/fulltext"; + $this->method = "POST"; + return $this; + } + + /** + * 查询短信发送记录 + * https://developer.qiniu.com/sms/api/5852/query-send-sms + * @return $this + */ + public function messages(): self + { + $this->url = "https://sms.qiniuapi.com/v1/messages"; + $this->method = "GET"; + return $this; + } + + /** + * 创建签名 + * https://developer.qiniu.com/sms/api/5844/sms-api-create-signature + * @return $this + */ + public function signature(): self + { + $this->url = "https://sms.qiniuapi.com/v1/signature"; + $this->method = "POST"; + return $this; + } + + /** + * 查询签名 + * https://developer.qiniu.com/sms/api/5844/sms-api-create-signature + * @return $this + */ + public function signatureQuery(): self + { + $this->url = "https://sms.qiniuapi.com/v1/signature"; + $this->method = "GET"; + $this->contentType = "application/x-www-form-urlencoded"; + return $this; + } + + /** + * 查询单个签名信息 + * https://developer.qiniu.com/sms/api/5970/query-a-single-signature + * @param $id + * @return $this + * @throws DtaException + */ + public function signatureQueryId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/signature/{$id}"; + $this->method = "GET"; + return $this; + } + + /** + * 编辑签名 + * https://developer.qiniu.com/sms/api/5890/sms-api-edit-signature + * @param $id + * @return $this + * @throws DtaException + */ + public function signatureEditId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/signature/{$id}"; + $this->method = "PUT"; + return $this; + } + + /** + * 删除签名 + * https://developer.qiniu.com/sms/api/5891/sms-api-delete-signature + * @param $id + * @return $this + * @throws DtaException + */ + public function signatureDelId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/signature/{$id}"; + $this->method = "DELETE"; + return $this; + } + + /** + * 创建模板 + * https://developer.qiniu.com/sms/api/5893/sms-api-create-template + * @return $this + */ + public function template(): self + { + $this->url = "https://sms.qiniuapi.com/v1/template"; + $this->method = "POST"; + return $this; + } + + /** + * 查询模板 + * https://developer.qiniu.com/sms/api/5894/sms-api-query-template + * @return $this + */ + public function templateQuery(): self + { + $this->url = "https://sms.qiniuapi.com/v1/template"; + $this->method = "GET"; + return $this; + } + + /** + * 查询单个模版信息 + * https://developer.qiniu.com/sms/api/5969/query-a-single-template + * @param $id + * @return $this + * @throws DtaException + */ + public function templateQueryId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/template/{$id}"; + $this->method = "GET"; + return $this; + } + + /** + * 编辑签名 + * https://developer.qiniu.com/sms/api/5895/sms-api-edit-template + * @param $id + * @return $this + * @throws DtaException + */ + public function templateEditId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/template/{$id}"; + $this->method = "PUT"; + return $this; + } + + /** + * 删除签名 + * https://developer.qiniu.com/sms/api/5896/sms-api-delete-template + * @param $id + * @return $this + * @throws DtaException + */ + public function templateDelId($id): self + { + if (empty($id)) { + throw new DtaException('请检查id参数'); + } + $this->url = "https://sms.qiniuapi.com/v1/template/{$id}"; + $this->method = "DELETE"; + return $this; + } + + /** + * 返回数组数据 + * @return array|mixed + * @throws DtaException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function toArray() + { + //首先检测是否支持curl + if (!extension_loaded("curl")) { + throw new HttpException(404, '请开启curl模块!'); + } + $this->http(); + // 正常 + if (is_array($this->output)) { + return $this->output; + } + if (is_object($this->output)) { + $this->output = $this->object2array($this->output); + return $this->output; + } + $this->output = json_decode($this->output, true); + return $this->output; + } + + /** + * @param $object + * @return array + */ + private function object2array(&$object): array + { + if (is_object($object)) { + $arr = (array)($object); + } else { + $arr = &$object; + } + if (is_array($arr)) { + foreach ($arr as $varName => $varValue) { + $arr[$varName] = $this->object2array($varValue); + } + } + return $arr; + } + + /** + * 网络请求 + * @return $this + * @throws DtaException + * @throws \GuzzleHttp\Exception\GuzzleException + */ + private function http(): self + { + if (empty($this->accessKey)) { + throw new DtaException('请检查accessKey参数'); + } + if (empty($this->secretKey)) { + throw new DtaException('请检查secretKey参数'); + } + $headers = [ + 'Authorization' => $this->authentication(), + 'Content-Type' => $this->contentType + ]; + + $auth = new Auth($this->accessKey, $this->secretKey); + $recToken = $auth->authorizationV2($this->url, $this->method, json_encode($this->param), $this->contentType); + $rtcToken['Content-Type'] = $this->contentType; + dump($recToken); + dump($this->url . "?" . http_build_query($this->param)); + $ret = Client::get($this->url . "?" . http_build_query($this->param), $recToken); + dump($ret); + $this->output = $ret->json(); + return $this; + } + + /** + * 服务鉴权 + * https://developer.qiniu.com/sms/api/5842/sms-api-authentication + * @return string + */ + private function authentication() + { + $url = parse_url($this->url); + $data = $url['path'] ?? ''; + if (isset($url['query'])) { + $data .= '?' . $url['query']; + } + $data .= "\n"; + if (isset($this->param) && $this->contentType === 'application/x-www-form-urlencoded') { + $data .= json_encode($this->param); + } + return $this->sign($data); + } + + /** + * @param $data + * @return string + */ + private function sign($data) + { + $sign = hash_hmac('sha1', $data, $this->secretKey, true); + return "Qiniu " . sprintf('%s:%s', $this->accessKey, $this->encode($sign)); + } + + /** + * @param $string + * @return string|string[] + */ + private function encode($string) + { + $find = ['+', '/']; + $replace = ['-', '_']; + return str_replace($find, $replace, base64_encode($string)); + } +} \ No newline at end of file diff --git a/src/service/wechat/MiniService.php b/src/service/wechat/MiniService.php index aae86e9..9b4bd04 100644 --- a/src/service/wechat/MiniService.php +++ b/src/service/wechat/MiniService.php @@ -377,6 +377,231 @@ class MiniService extends Service return json_decode($result, true); } + /** + * 【小程序直播】直播间管理接口 - 创建直播间 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#1 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastRoomCreate(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + /** + * 【小程序直播】直播间管理接口 - 获取直播间列表 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#2 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGetLiveInfos(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + /** + * 【小程序直播】直播间管理接口 - 获取直播间回放 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#3 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGetLiveInfo(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + /** + * 【小程序直播】直播间管理接口 - 直播间导入商品 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#4 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastRoomAddGoods(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + /** + * 【小程序直播】直播商品管理接口 - 商品添加并提审 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#1 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsAdd(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + /** + * 【小程序直播】直播商品管理接口 - 撤回审核 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#2 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsResetAudit(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + + /** + * 【小程序直播】直播商品管理接口 - 重新提交审核 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#3 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsAudit(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + + /** + * 【小程序直播】直播商品管理接口 - 删除商品 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#4 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsDelete(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + + /** + * 【小程序直播】直播商品管理接口 - 更新商品 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#5 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsUpdate(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + + /** + * 【小程序直播】直播商品管理接口 - 获取商品状态 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#6 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGetGoodsWarehouse(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + + + /** + * 【小程序直播】直播商品管理接口 - 获取商品列表 + * https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html#7 + * @param array $data + * @return array|bool|mixed|string + * @throws DbException + * @throws DtaException + */ + public function broadcastGoodsGetAppRoved(array $data = []) + { + // 获取数据 + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token={$accessToken['access_token']}"; + return HttpService::instance() + ->url($url) + ->data($data) + ->post() + ->toArray(); + } + /** * 获取小程序全局唯一后台接口调用凭据(access_token) * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html -- GitLab