add clear
This commit is contained in:
+11
-163
@@ -8,35 +8,12 @@
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\Result;
|
||||
use wchat\WxClient;
|
||||
use wchat\Miniprogarampage;
|
||||
use common\Decode;
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
|
||||
class Account extends Miniprogarampage
|
||||
class Account extends SmallProgram
|
||||
{
|
||||
|
||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
private $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
||||
private $publicInfo = 'https://api.weixin.qq.com/cgi-bin/user/info?';
|
||||
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||
|
||||
private $savePath = __DIR__ . '/../../../';
|
||||
|
||||
|
||||
private $OK = 0;
|
||||
private $IllegalAesKey = -41001;
|
||||
private $IllegalIv = -41002;
|
||||
private $IllegalBuffer = -41003;
|
||||
private $DecodeBase64Error = -41004;
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
public function setSavePath($path)
|
||||
{
|
||||
$this->savePath = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return Result
|
||||
@@ -53,31 +30,12 @@ class Account extends Miniprogarampage
|
||||
}
|
||||
|
||||
$this->request->setHost('api.q.qq.com');
|
||||
$this->request->setMethod(WxClient::GET);
|
||||
$this->request->setMethod(HttpClient::GET);
|
||||
$this->request->addHeader('Content-Type', 'text/xml');
|
||||
|
||||
return $this->request->get('sns/jscode2session', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openid
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getPublicUserInfo($openid)
|
||||
{
|
||||
$query = [
|
||||
'access_token' => $this->getAccessToken(),
|
||||
'openid' => $openid,
|
||||
'lang' => 'zh_CN'
|
||||
];
|
||||
|
||||
$this->request->setMethod(WxClient::GET);
|
||||
$this->request->setIsSSL(true);
|
||||
return $this->request->get($this->publicInfo, $query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
@@ -94,122 +52,12 @@ class Account extends Miniprogarampage
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, $asArray = false)
|
||||
{
|
||||
$config = QqSDK::getMiniProGaRamPage()->getConfig();
|
||||
if (strlen($sessionKey) != 24) {
|
||||
throw new \Exception('encodingAesKey 非法', $this->IllegalAesKey);
|
||||
}
|
||||
|
||||
$aesKey = base64_decode($sessionKey);
|
||||
if (strlen($iv) != 24) {
|
||||
throw new \Exception('base64解密失败', $this->IllegalIv);
|
||||
}
|
||||
|
||||
$aesIV = base64_decode($iv);
|
||||
$aesCipher = base64_decode($encryptedData);
|
||||
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, OPENSSL_RAW_DATA, $aesIV);
|
||||
if ($result === false) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
$dataObj = json_decode($result);
|
||||
if ($dataObj->watermark->appid != $config->getAppid()) {
|
||||
throw new \Exception('aes 解密失败', $this->IllegalBuffer);
|
||||
}
|
||||
|
||||
if ($asArray) {
|
||||
return get_object_vars($dataObj);
|
||||
}
|
||||
|
||||
return $dataObj;
|
||||
$decode = new Decode();
|
||||
$decode->setAppId($this->config->getAppid());
|
||||
$decode->setIv($iv);
|
||||
$decode->setEncryptedData($encryptedData);
|
||||
$decode->setSessionKey($sessionKey);
|
||||
return $decode->decode($asArray);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createwxaqrcode($path, $width)
|
||||
{
|
||||
$url = $this->wxaqr . $this->getAccessToken();
|
||||
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacode($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacode . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacodeunlimit($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacodeunlimit . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $body
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveByPath($body)
|
||||
{
|
||||
if (!is_null($json = json_decode($body))) {
|
||||
throw new \Exception($json['errmsg'], $json['errcode']);
|
||||
}
|
||||
|
||||
$push = md5_file($body) . '.png';
|
||||
file_put_contents($this->savePath . $push, $this->savePath);
|
||||
return $this->savePath . $push;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
class GamePrePay extends SmallProgram
|
||||
{
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/json/openApiPay/GamePrePay?access_token=';
|
||||
|
||||
|
||||
}
|
||||
-314
@@ -1,314 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
use wchat\Result;
|
||||
use wchat\WxClient;
|
||||
|
||||
class Message extends Miniprogarampage
|
||||
{
|
||||
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 $msgData = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $openid
|
||||
*/
|
||||
public function setOpenid(string $openid)
|
||||
{
|
||||
$this->openid = $openid;
|
||||
$this->msgData['touser'] = $openid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendTextNews(string $content)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'text';
|
||||
$this->msgData['text[content]'] = $content;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendImageNews(string $media_id)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'image';
|
||||
$this->msgData['image[media_id]'] = $media_id;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendVoiceNews(string $media_id)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'voice';
|
||||
$this->msgData['voice[media_id]'] = $media_id;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $media_id
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendMpNewsNews(string $media_id)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'mpnews';
|
||||
$this->msgData['mpnews[media_id]'] = $media_id;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @param string $url
|
||||
* @param string $picurl
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendNewsNews(string $title, string $description, string $url, string $picurl)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'news';
|
||||
$this->msgData['news[articles][0][title]'] = $title;
|
||||
$this->msgData['news[articles][0][description]'] = $description;
|
||||
$this->msgData['news[articles][0][url]'] = $url;
|
||||
$this->msgData['news[articles][0][picurl]'] = $picurl;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendCardNews(string $title)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'wxcard';
|
||||
$this->msgData['wxcard[card_id]'] = $title;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $media_id
|
||||
* @param string $thumb_media_id
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendVideoNews(string $media_id, string $thumb_media_id, string $title, string $description)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'video';
|
||||
$this->msgData['video[media_id]'] = $media_id;
|
||||
$this->msgData['video[thumb_media_id]'] = $thumb_media_id;
|
||||
$this->msgData['video[title]'] = $title;
|
||||
$this->msgData['video[description]'] = $description;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $musicurl
|
||||
* @param string $hqmusicurl
|
||||
* @param string $thumb_media_id
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendMusicNews(string $musicurl, string $hqmusicurl, string $thumb_media_id, string $title, string $description)
|
||||
{
|
||||
$this->msgData['msgtype'] = 'music';
|
||||
$this->msgData['music[title]'] = $title;
|
||||
$this->msgData['music[description]'] = $description;
|
||||
$this->msgData['music[musicurl]'] = $musicurl;
|
||||
$this->msgData['music[hqmusicurl]'] = $hqmusicurl;
|
||||
$this->msgData['music[thumb_media_id]'] = $thumb_media_id;
|
||||
|
||||
return $this->sendKefuMsg();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $head_content
|
||||
* @param string $tail_content
|
||||
* @param array $menus
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function sendMenuNews(string $head_content, string $tail_content, array $menus = [])
|
||||
{
|
||||
$this->msgData['msgtype'] = 'msgmenu';
|
||||
$this->msgData['msgmenu[head_content]'] = $head_content;
|
||||
$this->msgData['msgmenu[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();
|
||||
}
|
||||
|
||||
private $index = 0;
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @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;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'])) {
|
||||
throw new \Exception('暂不支持的文件类型');
|
||||
}
|
||||
|
||||
$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}";
|
||||
}
|
||||
|
||||
$mime = mime_content_type($filePath);
|
||||
|
||||
$real_path = new \CURLFile(realpath($filePath));
|
||||
|
||||
$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(WxClient::POST);
|
||||
|
||||
/** @var Result $body */
|
||||
$data = $this->request->post($url, $data);
|
||||
if (!$data->isResultsOK()) {
|
||||
throw new \Exception($data->getMessage());
|
||||
}
|
||||
|
||||
return $data->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mime
|
||||
* @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('不支持的文件格式');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function sendKefuMsg()
|
||||
{
|
||||
$data = json_encode($this->msgData, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$url = '/cgi-bin/message/custom/send?access_token=' . $this->getAccessToken();
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
|
||||
/** @var Result $body */
|
||||
$body = $this->request->post($url, $data);
|
||||
|
||||
if (!$body->isResultsOK()) {
|
||||
throw new \Exception($body->getMessage());
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -3,10 +3,9 @@
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
use wchat\Help;
|
||||
use common\Help;
|
||||
|
||||
class Notify extends Miniprogarampage
|
||||
class Notify extends SmallProgram
|
||||
{
|
||||
public $appid = '';
|
||||
public $mch_id = '';
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 9:49
|
||||
*/
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
use wchat\Result;
|
||||
|
||||
class PublicTemplate extends Miniprogarampage
|
||||
{
|
||||
|
||||
private $keywords = [];
|
||||
private $templateId = '';
|
||||
private $first = '';
|
||||
private $remark = '';
|
||||
private $openId = '';
|
||||
private $defaultUrl = 'http://weixin.qq.com/download';
|
||||
private $sendUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send';
|
||||
private $miniprogram = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateId
|
||||
*/
|
||||
public function setTemplateId(string $templateId)
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $openId
|
||||
*/
|
||||
public function setOpenId(string $openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $defaultUrl
|
||||
*/
|
||||
public function setDefaultUrl(string $defaultUrl)
|
||||
{
|
||||
$this->defaultUrl = $defaultUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $context
|
||||
* @param string $color
|
||||
*/
|
||||
public function replaceKeyword($name, $context, $color = '')
|
||||
{
|
||||
$this->keywords[$name] = ['value' => $context, 'color' => $color];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $context
|
||||
* @param null $color
|
||||
*/
|
||||
public function addKeyword($name, $context, $color = null)
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords[$name] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $context
|
||||
* @param string $color
|
||||
*/
|
||||
public function setFirst($context, $color = '#f00')
|
||||
{
|
||||
$this->first = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $context
|
||||
* @param string $color
|
||||
*/
|
||||
public function setRemark($context, $color = '#000')
|
||||
{
|
||||
$this->remark = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $appid
|
||||
* @param $pagepath
|
||||
*/
|
||||
public function setMiniprogram($appid, $pagepath)
|
||||
{
|
||||
$this->miniprogram = [
|
||||
'appid' => $appid,
|
||||
'pagepath' => $pagepath
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$url = $this->sendUrl . '?access_token=' . $this->getAccessToken();
|
||||
|
||||
$keywords = $this->keywords;
|
||||
$keywords['first'] = $this->first;
|
||||
$keywords['remark'] = $this->remark;
|
||||
|
||||
$default = [
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"url" => $this->defaultUrl,
|
||||
"data" => $keywords,
|
||||
];
|
||||
|
||||
if (!empty($this->miniprogram)) {
|
||||
$default['miniprogram'] = $this->miniprogram;
|
||||
}
|
||||
|
||||
$params = json_encode($default, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->addHeader('content-type', 'application/json');
|
||||
|
||||
$result = $this->request->post($url, $params);
|
||||
$result->append('postBody', $params);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\WxClient;
|
||||
use wchat\Config;
|
||||
|
||||
class QqSDK
|
||||
{
|
||||
|
||||
/** @var static $instance */
|
||||
private static $instance = null;
|
||||
|
||||
/** @var Config $config */
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function getMiniProGaRamPage()
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
static::$instance = new QqSDK();
|
||||
}
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @return $this
|
||||
*/
|
||||
public function setConfig(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Template
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
return Template::getInstance($this->config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return PublicTemplate
|
||||
*/
|
||||
public function getPublicTemplate()
|
||||
{
|
||||
return PublicTemplate::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account
|
||||
*/
|
||||
public function getAccount()
|
||||
{
|
||||
return Account::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Message
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return Message::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Recharge
|
||||
*/
|
||||
public function getRecharge()
|
||||
{
|
||||
return Recharge::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Notify
|
||||
*/
|
||||
public function getNotify()
|
||||
{
|
||||
return Notify::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WxClient
|
||||
*/
|
||||
public function getClient()
|
||||
{
|
||||
$client = WxClient::getInstance();
|
||||
$client->setAgent($this->config->getAgent());
|
||||
return $client;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Token
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
return Token::getInstance($this->config);
|
||||
}
|
||||
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
|
||||
class QrCode extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
private $wxaqr = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
private $getwxacode = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=';
|
||||
private $getwxacodeunlimit = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||
|
||||
private $savePath = __DIR__ . '/../../../';
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
public function setSavePath($path)
|
||||
{
|
||||
$this->savePath = $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createwxaqrcode($path, $width)
|
||||
{
|
||||
$url = $this->wxaqr . $this->getAccessToken();
|
||||
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacode($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacode . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return array|mixed|Result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getwxacodeunlimit($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '')
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
|
||||
$url = $this->getwxacodeunlimit . $this->getAccessToken();
|
||||
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->setCallback([$this, 'saveByPath']);
|
||||
return $this->request->post($url, $sendBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $body
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveByPath($body)
|
||||
{
|
||||
if (!is_null($json = json_decode($body))) {
|
||||
throw new \Exception($json['errmsg'], $json['errcode']);
|
||||
}
|
||||
|
||||
$push = md5_file($body) . '.png';
|
||||
file_put_contents($this->savePath . $push, $this->savePath);
|
||||
return $this->savePath . $push;
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -8,12 +8,11 @@
|
||||
|
||||
namespace qq;
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
use wchat\Result;
|
||||
use wchat\Help;
|
||||
use wchat\WxClient;
|
||||
use common\HttpClient;
|
||||
use common\Result;
|
||||
use common\Help;
|
||||
|
||||
class Recharge extends Miniprogarampage
|
||||
class Recharge extends SmallProgram
|
||||
{
|
||||
private $money = 0;
|
||||
|
||||
@@ -175,7 +174,7 @@ class Recharge extends Miniprogarampage
|
||||
private function send($url, $data)
|
||||
{
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->setMethod(WxClient::POST);
|
||||
$this->request->setMethod(HttpClient::POST);
|
||||
$this->request->addHeader('Content-Type', 'text/xml');
|
||||
return $this->request->send($url, $data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Miniprogarampage;
|
||||
|
||||
class SmallProgram extends Miniprogarampage
|
||||
{
|
||||
|
||||
protected static $instance;
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/getToken';
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function generateAccess_token()
|
||||
{
|
||||
if (!empty($this->config->getToken())) {
|
||||
return $this->config->getToken();
|
||||
}
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
];
|
||||
$param = $this->request->get($this->url, $query);
|
||||
if (!$param->isResultsOK()) {
|
||||
return null;
|
||||
}
|
||||
return $param->getData('access_token');
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace qq;
|
||||
|
||||
|
||||
use common\Result;
|
||||
|
||||
class Subject extends SmallProgram
|
||||
{
|
||||
|
||||
|
||||
private $keywords = [];
|
||||
private $templateId = '';
|
||||
private $openId = '';
|
||||
private $defaultUrl = '';
|
||||
private $page = 'pages/index/index';
|
||||
private $emphasis_keyword = '';
|
||||
|
||||
private $sendUrl = 'https://api.q.qq.com/api/json/subscribe/SendSubscriptionMessage';
|
||||
|
||||
|
||||
/**
|
||||
* @param array $keywords
|
||||
*/
|
||||
public function setKeywords(array $keywords)
|
||||
{
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateId
|
||||
*/
|
||||
public function setTemplateId(string $templateId)
|
||||
{
|
||||
$this->templateId = $templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $openId
|
||||
*/
|
||||
public function setOpenId(string $openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $defaultUrl
|
||||
*/
|
||||
public function setDefaultUrl(string $defaultUrl)
|
||||
{
|
||||
$this->defaultUrl = $defaultUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $page
|
||||
*/
|
||||
public function setPage(string $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $emphasis_keyword
|
||||
*/
|
||||
public function setEmphasisKeyword(string $emphasis_keyword)
|
||||
{
|
||||
$this->emphasis_keyword = $emphasis_keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $index
|
||||
* @param $context
|
||||
* @param $color
|
||||
*/
|
||||
public function replaceKeyword($index, $context, $color = '')
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . $index] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $color
|
||||
* @param $context
|
||||
*/
|
||||
public function addKeyword($context, $color = null)
|
||||
{
|
||||
if (empty($color)) {
|
||||
$color = '#000';
|
||||
}
|
||||
$this->keywords['keyword' . (count($this->keywords) + 1)] = [
|
||||
'value' => $context,
|
||||
'color' => $color
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws \Exception
|
||||
*
|
||||
* 奴隶交易通知
|
||||
*/
|
||||
public function sendTemplate()
|
||||
{
|
||||
$url = $this->sendUrl . '?access_token=' . $this->config->getAccessToken();
|
||||
$params = json_encode([
|
||||
"touser" => $this->openId,
|
||||
"template_id" => $this->templateId,
|
||||
"page" => $this->page,
|
||||
"data" => $this->keywords,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
if (!empty($this->emphasis_keyword)) {
|
||||
$params['emphasis_keyword'] = $this->emphasis_keyword;
|
||||
}
|
||||
|
||||
$this->request->setIsSSL(true);
|
||||
$this->request->addHeader('content-type', 'application/json');
|
||||
|
||||
$result = $this->request->post($url, $params);
|
||||
$result->append('postBody', $params);
|
||||
|
||||
$this->openId = '';
|
||||
$this->keywords = [];
|
||||
$this->templateId = '';
|
||||
$this->page = '';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -9,12 +9,9 @@
|
||||
namespace qq;
|
||||
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
use wchat\Result;
|
||||
use wchat\Help;
|
||||
use wchat\WxClient;
|
||||
use common\Result;
|
||||
|
||||
class Template extends Miniprogarampage
|
||||
class Template extends SmallProgram
|
||||
{
|
||||
|
||||
private $keywords = [];
|
||||
|
||||
+1
-20
@@ -4,29 +4,10 @@
|
||||
namespace qq;
|
||||
|
||||
|
||||
use wchat\Miniprogarampage;
|
||||
|
||||
class Token extends Miniprogarampage
|
||||
class Token extends SmallProgram
|
||||
{
|
||||
|
||||
private $url = 'https://api.q.qq.com/api/getToken';
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function generateAccess_token()
|
||||
{
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
];
|
||||
$param = $this->request->get($this->url, $query);
|
||||
if (!$param->isResultsOK()) {
|
||||
return null;
|
||||
}
|
||||
return $param->getData('access_token');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user