From f550950d61f83322ca865a1dc2fe3e069495c9e6 Mon Sep 17 00:00:00 2001 From: liyifei <119422342@qq.com> Date: Thu, 29 Nov 2018 08:21:27 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mini/template/Template.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/mini/template/Template.php b/src/mini/template/Template.php index 61f84ad..941da4e 100644 --- a/src/mini/template/Template.php +++ b/src/mini/template/Template.php @@ -10,6 +10,7 @@ namespace abei2017\wx\mini\template; +use abei2017\wx\core\AccessToken; use abei2017\wx\core\Driver; use Yii; use yii\httpclient\Client; @@ -21,10 +22,19 @@ * @link https://nai8.me/yii2wx * @package abei2017\wx\mini\template */ -class Template extends Driver { +class Template extends Driver +{ const API_SEND_TMPL = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='; + private $accessToken = null; + + public function init() + { + parent::init(); + $this->accessToken = (new AccessToken(['conf' => $this->conf, 'httpClient' => $this->httpClient]))->getToken(); + } + /** * 发送模板消息 * @@ -34,17 +44,18 @@ class Template extends Driver { * @param $data * @param array $extra */ - public function send($toUser,$templateId,$formId,$data,$extra = []){ + public function send($toUser, $templateId, $formId, $data, $extra = []) + { $params = array_merge([ - 'touser'=>$toUser, - 'template_id'=>$templateId, - 'form_id'=>$formId, - 'data'=>$data, - ],$extra); - $response = $this->post(self::API_SEND_TMPL.$this->accessToken->getToken(),$params)->setFormat(Client::FORMAT_JSON)->send(); + 'touser' => $toUser, + 'template_id' => $templateId, + 'form_id' => $formId, + 'data' => $data, + ], $extra); + $response = $this->post(self::API_SEND_TMPL . $this->accessToken->getToken(), $params)->setFormat(Client::FORMAT_JSON)->send(); return $response->getContent(); } - + } \ No newline at end of file From ef2656f2b1ade42ecadaa6c0bb2b473fae65ada6 Mon Sep 17 00:00:00 2001 From: liyifei <119422342@qq.com> Date: Fri, 30 Nov 2018 16:43:20 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mini/template/Template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mini/template/Template.php b/src/mini/template/Template.php index 941da4e..9f52dab 100644 --- a/src/mini/template/Template.php +++ b/src/mini/template/Template.php @@ -52,7 +52,7 @@ public function send($toUser, $templateId, $formId, $data, $extra = []) 'form_id' => $formId, 'data' => $data, ], $extra); - $response = $this->post(self::API_SEND_TMPL . $this->accessToken->getToken(), $params)->setFormat(Client::FORMAT_JSON)->send(); + $response = $this->post(self::API_SEND_TMPL . $this->accessToken, $params)->setFormat(Client::FORMAT_JSON)->send(); return $response->getContent(); } From fe9f9d21c09da58f5252c0778c81c0f66288a91e Mon Sep 17 00:00:00 2001 From: liyifei <119422342@qq.com> Date: Fri, 6 Sep 2019 11:37:50 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mini/payment/Pay.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mini/payment/Pay.php b/src/mini/payment/Pay.php index f0c310c..e891c96 100755 --- a/src/mini/payment/Pay.php +++ b/src/mini/payment/Pay.php @@ -71,6 +71,7 @@ protected function prepare($attrs = []){ $attrs['sign'] = Util::makeSign($attrs,$this->conf['payment']['key']); $response = $this->post(self::PREPARE_URL,$attrs)->setFormat(Client::FORMAT_XML)->send(); + $response->setFormat(Client::FORMAT_XML); return $this->prepare = (object)$response->getData(); } From 32bd33a43303b9900b685265ae2866ac60c040a3 Mon Sep 17 00:00:00 2001 From: LEEYIFIEI <119422342@qq.com> Date: Fri, 27 Sep 2019 11:41:11 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=9B=91=E6=B5=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + composer.lock | 518 +++++++++++++++++++++++++++++++++ src/Application.php | 83 +++--- src/core/AccessToken.php | 30 +- src/core/Driver.php | 34 ++- src/example/.gitignore | 2 + src/example/.gitkeep | 0 src/example/common.php | 35 +++ src/example/imgcheck.php | 14 + src/example/msgcheck.php | 13 + src/mini/seccheck/ImgCheck.php | 68 +++++ src/mini/seccheck/MsgCheck.php | 52 ++++ 12 files changed, 791 insertions(+), 60 deletions(-) create mode 100644 .gitignore create mode 100644 composer.lock create mode 100644 src/example/.gitignore create mode 100644 src/example/.gitkeep create mode 100644 src/example/common.php create mode 100644 src/example/imgcheck.php create mode 100644 src/example/msgcheck.php create mode 100644 src/mini/seccheck/ImgCheck.php create mode 100644 src/mini/seccheck/MsgCheck.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb756e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +.idea \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..6a06cd6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,518 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "14819a37dc95fc2e5a0f2b22d033792b", + "packages": [ + { + "name": "bower-asset/inputmask", + "version": "3.3.11", + "source": { + "type": "git", + "url": "https://github.com/RobinHerbots/Inputmask.git", + "reference": "5e670ad62f50c738388d4dcec78d2888505ad77b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/5e670ad62f50c738388d4dcec78d2888505ad77b", + "reference": "5e670ad62f50c738388d4dcec78d2888505ad77b", + "shasum": "" + }, + "require": { + "bower-asset/jquery": ">=1.7" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": [ + "./dist/inputmask/inputmask.js", + "./dist/inputmask/inputmask.extensions.js", + "./dist/inputmask/inputmask.date.extensions.js", + "./dist/inputmask/inputmask.numeric.extensions.js", + "./dist/inputmask/inputmask.phone.extensions.js", + "./dist/inputmask/jquery.inputmask.js", + "./dist/inputmask/global/document.js", + "./dist/inputmask/global/window.js", + "./dist/inputmask/phone-codes/phone.js", + "./dist/inputmask/phone-codes/phone-be.js", + "./dist/inputmask/phone-codes/phone-nl.js", + "./dist/inputmask/phone-codes/phone-ru.js", + "./dist/inputmask/phone-codes/phone-uk.js", + "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js", + "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js", + "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.js", + "./dist/inputmask/bindings/inputmask.binding.js" + ], + "bower-asset-ignore": [ + "**/*", + "!dist/*", + "!dist/inputmask/*", + "!dist/min/*", + "!dist/min/inputmask/*" + ] + }, + "license": [ + "http://opensource.org/licenses/mit-license.php" + ], + "description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.", + "keywords": [ + "form", + "input", + "inputmask", + "jquery", + "mask", + "plugins" + ], + "time": "2017-11-21T11:46:23+00:00" + }, + { + "name": "bower-asset/jquery", + "version": "3.4.1", + "source": { + "type": "git", + "url": "https://github.com/jquery/jquery-dist.git", + "reference": "15bc73803f76bc53b654b9fdbbbc096f56d7c03d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/15bc73803f76bc53b654b9fdbbbc096f56d7c03d", + "reference": "15bc73803f76bc53b654b9fdbbbc096f56d7c03d", + "shasum": "" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": "dist/jquery.js", + "bower-asset-ignore": [ + "package.json" + ] + }, + "license": [ + "MIT" + ], + "keywords": [ + "browser", + "javascript", + "jquery", + "library" + ], + "time": "2019-05-01T21:19:28+00:00" + }, + { + "name": "bower-asset/punycode", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/bestiejs/punycode.js.git", + "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3", + "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3", + "shasum": "" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": "punycode.js", + "bower-asset-ignore": [ + "coverage", + "tests", + ".*", + "component.json", + "Gruntfile.js", + "node_modules", + "package.json" + ] + }, + "time": "2014-10-22T12:02:42+00:00" + }, + { + "name": "bower-asset/yii2-pjax", + "version": "2.0.7.1", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/jquery-pjax.git", + "reference": "aef7b953107264f00234902a3880eb50dafc48be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/aef7b953107264f00234902a3880eb50dafc48be", + "reference": "aef7b953107264f00234902a3880eb50dafc48be", + "shasum": "" + }, + "require": { + "bower-asset/jquery": ">=1.8" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": "./jquery.pjax.js", + "bower-asset-ignore": [ + ".travis.yml", + "Gemfile", + "Gemfile.lock", + "CONTRIBUTING.md", + "vendor/", + "script/", + "test/" + ] + }, + "license": [ + "MIT" + ], + "time": "2017-10-12T10:11:14+00:00" + }, + { + "name": "cebe/markdown", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/cebe/markdown.git", + "reference": "9bac5e971dd391e2802dca5400bbeacbaea9eb86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cebe/markdown/zipball/9bac5e971dd391e2802dca5400bbeacbaea9eb86", + "reference": "9bac5e971dd391e2802dca5400bbeacbaea9eb86", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "lib-pcre": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "cebe/indent": "*", + "facebook/xhprof": "*@dev", + "phpunit/phpunit": "4.1.*" + }, + "bin": [ + "bin/markdown" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "cebe\\markdown\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Carsten Brandt", + "email": "mail@cebe.cc", + "homepage": "http://cebe.cc/", + "role": "Creator" + } + ], + "description": "A super fast, highly extensible markdown parser for PHP", + "homepage": "https://github.com/cebe/markdown#readme", + "keywords": [ + "extensible", + "fast", + "gfm", + "markdown", + "markdown-extra" + ], + "time": "2018-03-26T11:24:36+00:00" + }, + { + "name": "ezyang/htmlpurifier", + "version": "v4.11.0", + "source": { + "type": "git", + "url": "https://github.com/ezyang/htmlpurifier.git", + "reference": "83ab08bc1af7d808a9e0fbf024f1c24bfd73c0a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/83ab08bc1af7d808a9e0fbf024f1c24bfd73c0a7", + "reference": "83ab08bc1af7d808a9e0fbf024f1c24bfd73c0a7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.2" + }, + "require-dev": { + "simpletest/simpletest": "dev-master#72de02a7b80c6bb8864ef9bf66d41d2f58f826bd" + }, + "type": "library", + "autoload": { + "psr-0": { + "HTMLPurifier": "library/" + }, + "files": [ + "library/HTMLPurifier.composer.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Edward Z. Yang", + "email": "admin@htmlpurifier.org", + "homepage": "http://ezyang.com" + } + ], + "description": "Standards compliant HTML filter written in PHP", + "homepage": "http://htmlpurifier.org/", + "keywords": [ + "html" + ], + "time": "2019-07-14T18:58:38+00:00" + }, + { + "name": "yiisoft/yii2", + "version": "2.0.27", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-framework.git", + "reference": "6793f8f9b4cd891dbf475cfbb88cf480f74eaa85" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/6793f8f9b4cd891dbf475cfbb88cf480f74eaa85", + "reference": "6793f8f9b4cd891dbf475cfbb88cf480f74eaa85", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "bower-asset/inputmask": "~3.2.2 | ~3.3.5", + "bower-asset/jquery": "3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", + "bower-asset/punycode": "1.3.*", + "bower-asset/yii2-pjax": "~2.0.1", + "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0", + "ext-ctype": "*", + "ext-mbstring": "*", + "ezyang/htmlpurifier": "~4.6", + "lib-pcre": "*", + "php": ">=5.4.0", + "yiisoft/yii2-composer": "~2.0.4" + }, + "bin": [ + "yii" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Qiang Xue", + "email": "qiang.xue@gmail.com", + "homepage": "http://www.yiiframework.com/", + "role": "Founder and project lead" + }, + { + "name": "Alexander Makarov", + "email": "sam@rmcreative.ru", + "homepage": "http://rmcreative.ru/", + "role": "Core framework development" + }, + { + "name": "Maurizio Domba", + "homepage": "http://mdomba.info/", + "role": "Core framework development" + }, + { + "name": "Carsten Brandt", + "email": "mail@cebe.cc", + "homepage": "http://cebe.cc/", + "role": "Core framework development" + }, + { + "name": "Timur Ruziev", + "email": "resurtm@gmail.com", + "homepage": "http://resurtm.com/", + "role": "Core framework development" + }, + { + "name": "Paul Klimov", + "email": "klimov.paul@gmail.com", + "role": "Core framework development" + }, + { + "name": "Dmitry Naumenko", + "email": "d.naumenko.a@gmail.com", + "role": "Core framework development" + }, + { + "name": "Boudewijn Vahrmeijer", + "email": "info@dynasource.eu", + "homepage": "http://dynasource.eu", + "role": "Core framework development" + } + ], + "description": "Yii PHP Framework Version 2", + "homepage": "http://www.yiiframework.com/", + "keywords": [ + "framework", + "yii2" + ], + "time": "2019-09-18T13:04:16+00:00" + }, + { + "name": "yiisoft/yii2-composer", + "version": "2.0.8", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-composer.git", + "reference": "5c7ca9836cf80b34db265332a7f2f8438eb469b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/5c7ca9836cf80b34db265332a7f2f8438eb469b9", + "reference": "5c7ca9836cf80b34db265332a7f2f8438eb469b9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "require-dev": { + "composer/composer": "^1.0", + "phpunit/phpunit": "<7" + }, + "type": "composer-plugin", + "extra": { + "class": "yii\\composer\\Plugin", + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\composer\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Qiang Xue", + "email": "qiang.xue@gmail.com" + }, + { + "name": "Carsten Brandt", + "email": "mail@cebe.cc" + } + ], + "description": "The composer plugin for Yii extension installer", + "keywords": [ + "composer", + "extension installer", + "yii2" + ], + "time": "2019-07-16T13:22:30+00:00" + }, + { + "name": "yiisoft/yii2-httpclient", + "version": "2.0.11", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-httpclient.git", + "reference": "cf532447447216bd8cb167689ac18f4e7dc1c1a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-httpclient/zipball/cf532447447216bd8cb167689ac18f4e7dc1c1a7", + "reference": "cf532447447216bd8cb167689ac18f4e7dc1c1a7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "yiisoft/yii2": "~2.0.13" + }, + "require-dev": { + "phpunit/phpunit": "4.8.27|~5.7.21|^6.2" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\httpclient\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Paul Klimov", + "email": "klimov.paul@gmail.com" + } + ], + "description": "HTTP client extension for the Yii framework", + "keywords": [ + "curl", + "http", + "httpclient", + "yii2" + ], + "time": "2019-05-14T13:33:37+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.4" + }, + "platform-dev": [] +} diff --git a/src/Application.php b/src/Application.php index b76ec33..1cd7296 100644 --- a/src/Application.php +++ b/src/Application.php @@ -24,7 +24,8 @@ * @author abei * @package abei2017\wx */ -class Application extends Component { +class Application extends Component +{ /** * yii2-wx配置 @@ -47,42 +48,45 @@ class Application extends Component { * @var array */ public $classMap = [ - 'core'=>[ - 'accessToken'=>'abei2017\wx\core\AccessToken' + 'core' => [ + 'accessToken' => 'abei2017\wx\core\AccessToken' ], - 'mp'=>[ - 'base'=>'abei2017\wx\mp\core\Base', // 二维码 - 'qrcode'=>'abei2017\wx\mp\qrcode\Qrcode', // 二维码 - 'shorturl'=>'abei2017\wx\mp\qrcode\Shorturl', // 短地址 - 'server'=>'abei2017\wx\mp\server\Server', // 服务接口 - 'remark'=>'abei2017\wx\mp\user\Remark', // 会员备注 - 'user'=>'abei2017\wx\mp\user\User', // 会员管理 - 'tag'=>'abei2017\wx\mp\user\Tag', // 会员标签 - 'menu'=>'abei2017\wx\mp\menu\Menu', // 菜单 - 'js'=>'abei2017\wx\mp\js\Js', // JS - 'template'=>'abei2017\wx\mp\template\Template', // 消息模板 - 'pay'=>'abei2017\wx\mp\payment\Pay',// 支付接口 - 'mch'=>'abei2017\wx\mp\payment\Mch',// 企业付款 - 'redbag'=>'abei2017\wx\mp\payment\Redbag',// 红包 - 'oauth'=>'abei2017\wx\mp\oauth\OAuth',// web授权 - 'resource'=>'abei2017\wx\mp\resource\Resource',// 素材 - 'kf'=>'abei2017\wx\mp\kf\Kf',// 客服 - 'customService'=>'abei2017\wx\mp\kf\CustomService',// 群发 + 'mp' => [ + 'base' => 'abei2017\wx\mp\core\Base', // 二维码 + 'qrcode' => 'abei2017\wx\mp\qrcode\Qrcode', // 二维码 + 'shorturl' => 'abei2017\wx\mp\qrcode\Shorturl', // 短地址 + 'server' => 'abei2017\wx\mp\server\Server', // 服务接口 + 'remark' => 'abei2017\wx\mp\user\Remark', // 会员备注 + 'user' => 'abei2017\wx\mp\user\User', // 会员管理 + 'tag' => 'abei2017\wx\mp\user\Tag', // 会员标签 + 'menu' => 'abei2017\wx\mp\menu\Menu', // 菜单 + 'js' => 'abei2017\wx\mp\js\Js', // JS + 'template' => 'abei2017\wx\mp\template\Template', // 消息模板 + 'pay' => 'abei2017\wx\mp\payment\Pay',// 支付接口 + 'mch' => 'abei2017\wx\mp\payment\Mch',// 企业付款 + 'redbag' => 'abei2017\wx\mp\payment\Redbag',// 红包 + 'oauth' => 'abei2017\wx\mp\oauth\OAuth',// web授权 + 'resource' => 'abei2017\wx\mp\resource\Resource',// 素材 + 'kf' => 'abei2017\wx\mp\kf\Kf',// 客服 + 'customService' => 'abei2017\wx\mp\kf\CustomService',// 群发 ], - 'mini'=>[ - 'user'=>'abei2017\wx\mini\user\User', // 会员 - 'pay'=>'abei2017\wx\mini\payment\Pay', // 支付 - 'qrcode'=>'abei2017\wx\mini\qrcode\Qrcode', // 二维码&小程序码 - 'template'=>'abei2017\wx\mini\template\Template', // 模板消息 - 'custom'=>'abei2017\wx\mini\custom\Customer', - 'server'=>'abei2017\wx\mini\custom\Server', + 'mini' => [ + 'user' => 'abei2017\wx\mini\user\User', // 会员 + 'pay' => 'abei2017\wx\mini\payment\Pay', // 支付 + 'qrcode' => 'abei2017\wx\mini\qrcode\Qrcode', // 二维码&小程序码 + 'template' => 'abei2017\wx\mini\template\Template', // 模板消息 + 'custom' => 'abei2017\wx\mini\custom\Customer', + 'server' => 'abei2017\wx\mini\custom\Server', + 'imgcheck' => 'abei2017\wx\mini\seccheck\ImgCheck', // 图片内容监测 + 'msgcheck' => 'abei2017\wx\mini\seccheck\MsgCheck', // 文本内容监测 ] ]; - public function init(){ + public function init() + { parent::init(); $this->httpClient = new Client($this->httpConf); } @@ -92,24 +96,25 @@ public function init(){ * 此函数主要负责生成相关类的实例化对象并传递相关参数 * * @param $api string 类的映射名 - * @param array $extra 附加参数 + * @param array $extra 附加参数 * @throws Exception * @return object */ - public function driver($api,$extra = []){ + public function driver($api, $extra = []) + { - $api = explode('.',$api); - if(empty($api) OR isset($this->classMap[$api[0]][$api[1]]) == false){ + $api = explode('.', $api); + if (empty($api) OR isset($this->classMap[$api[0]][$api[1]]) == false) { throw new Exception('很抱歉,你输入的API不合法。'); } // 初始化conf - if(empty($this->conf)){ - if(isset(Yii::$app->params['wx']) == false){ + if (empty($this->conf)) { + if (isset(Yii::$app->params['wx']) == false) { throw new Exception('请在yii2的配置文件中设置配置项wx'); } - if(isset(Yii::$app->params['wx'][$api[0]]) == false){ + if (isset(Yii::$app->params['wx'][$api[0]]) == false) { throw new Exception("请在yii2的配置文件中设置配置项wx[{$api[0]}]"); } @@ -117,9 +122,9 @@ public function driver($api,$extra = []){ } $config = [ - 'conf'=>$this->conf, - 'httpClient'=>$this->httpClient, - 'extra'=>$extra, + 'conf' => $this->conf, + 'httpClient' => $this->httpClient, + 'extra' => $extra, ]; $config['class'] = $this->classMap[$api[0]][$api[1]]; diff --git a/src/core/AccessToken.php b/src/core/AccessToken.php index 2b3d3b7..f08dc77 100644 --- a/src/core/AccessToken.php +++ b/src/core/AccessToken.php @@ -22,7 +22,8 @@ * @package abei2017\wx\core\accessToken * @author abei */ -class AccessToken extends Driver { +class AccessToken extends Driver +{ // 获取access_token的接口地址 const API_TOKEN_GET = 'https://api.weixin.qq.com/cgi-bin/token'; @@ -37,18 +38,19 @@ class AccessToken extends Driver { * @author abei * @return string */ - public function getToken($cacheRefresh = false){ + public function getToken($cacheRefresh = false) + { $cacheKey = "{$this->cacheKey}-{$this->conf['app_id']}"; - if($cacheRefresh == true){ + if ($cacheRefresh == true) { Yii::$app->cache->delete($cacheKey); } $data = Yii::$app->cache->get($cacheKey); - if($data == false){ + if ($data == false) { $token = $this->getTokenFromServer(); $data = $token['access_token']; - Yii::$app->cache->set($cacheKey,$data,$token['expires_in']-600); + Yii::$app->cache->set($cacheKey, $data, $token['expires_in'] - 600); } return $data; @@ -61,23 +63,25 @@ public function getToken($cacheRefresh = false){ * @author abei * @throws \abei2017\wx\core\Exception */ - public function getTokenFromServer(){ + public function getTokenFromServer() + { $params = [ - 'grant_type'=>'client_credential', - 'appid'=>$this->conf['app_id'], - 'secret'=>$this->conf['secret'] + 'grant_type' => 'client_credential', + 'appid' => $this->conf['app_id'], + 'secret' => $this->conf['secret'] ]; - $response = $this->get(self::API_TOKEN_GET,$params)->send(); + $response = $this->get(self::API_TOKEN_GET, $params)->send(); - if($response->isOk == false){ + if ($response->isOk == false) { throw new Exception(self::ERROR_NO_RESPONSE); } $response->setFormat(Client::FORMAT_JSON); $data = $response->getData(); - if(!isset($data['access_token'])){ - throw new Exception($data['errmsg'],$data['errcode']); + + if (!isset($data['access_token'])) { + throw new Exception($data['errmsg'], $data['errcode']); } return $data; diff --git a/src/core/Driver.php b/src/core/Driver.php index bdc9b88..975e2a1 100644 --- a/src/core/Driver.php +++ b/src/core/Driver.php @@ -11,15 +11,16 @@ namespace abei2017\wx\core; -use abei2017\wx\helpers\Util; use yii\base\Component; +use yii\httpclient\Client; /** * 接口类 * 该类主要抽象出每个接口类必须的几个属性 * @package abei2017\wx\core */ -class Driver extends Component { +class Driver extends Component +{ /** * ERRORS @@ -28,13 +29,17 @@ class Driver extends Component { public $conf; public $extra; + /** + * @var Client + */ public $httpClient; /** * 生成一个request请求 * @return mixed */ - protected function request(){ + protected function request() + { return $this->httpClient->createRequest(); } @@ -47,13 +52,26 @@ protected function request(){ * @param $options array 操作项 * @return mixed */ - protected function get($url,$params = [], $headers = [], $options = []){ - return $this->httpClient->get($url,$params,$headers,$options); + protected function get($url, $params = [], $headers = [], $options = []) + { + return $this->httpClient->get($url, $params, $headers, $options); } - protected function post($url,$params = [], $headers = [], $options = []){ - return $this->httpClient->post($url,$params,$headers,$options); + protected function post($url, $params = [], $headers = [], $options = []) + { + return $this->httpClient->post($url, $params, $headers, $options); } - + protected function upload($url, $file, $params = [], $headers = [], $options = []) + { + list($fileField, $file) = $file; + return $this->httpClient + ->createRequest() + ->setUrl($url) + ->setMethod('POST') + ->addHeaders($headers) + ->addOptions($options) + ->setData($params) + ->addFile($fileField, $file); + } } \ No newline at end of file diff --git a/src/example/.gitignore b/src/example/.gitignore new file mode 100644 index 0000000..67d010b --- /dev/null +++ b/src/example/.gitignore @@ -0,0 +1,2 @@ +config.txt +runtime \ No newline at end of file diff --git a/src/example/.gitkeep b/src/example/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/example/common.php b/src/example/common.php new file mode 100644 index 0000000..a0e06a2 --- /dev/null +++ b/src/example/common.php @@ -0,0 +1,35 @@ +charset = 'UTF-8'); + +$application = new yii\web\Application([ + 'id' => 'example', + 'basePath' => dirname(__FILE__), + 'runtimePath' => dirname(__FILE__) . '/runtime', + 'components' => [ + 'cache' => [ + 'class' => 'yii\caching\FileCache', + 'cachePath' => '@runtime/cache' + ], + ] +]); + +$conf = file_get_contents('./config.txt'); +$conf = json_decode($conf, 1); + +$sdk = new \abei2017\wx\Application([ + 'conf' => [ + 'app_id' => $conf['appkey'], + 'secret' => $conf['appsecret'], + ] +]); + diff --git a/src/example/imgcheck.php b/src/example/imgcheck.php new file mode 100644 index 0000000..aae612c --- /dev/null +++ b/src/example/imgcheck.php @@ -0,0 +1,14 @@ +driver('mini.imgcheck'); +$response = $driver->check('https://ss2.bdstatic.com/8_V1bjqh_Q23odCf/pacific/1768717746.jpg', true); + +print_r($response); diff --git a/src/example/msgcheck.php b/src/example/msgcheck.php new file mode 100644 index 0000000..f53ed6b --- /dev/null +++ b/src/example/msgcheck.php @@ -0,0 +1,13 @@ +driver('mini.msgcheck'); + +var_dump($driver->check('操你妈')); \ No newline at end of file diff --git a/src/mini/seccheck/ImgCheck.php b/src/mini/seccheck/ImgCheck.php new file mode 100644 index 0000000..6318c17 --- /dev/null +++ b/src/mini/seccheck/ImgCheck.php @@ -0,0 +1,68 @@ +accessToken = (new AccessToken(['conf' => $this->conf, 'httpClient' => $this->httpClient]))->getToken(); + } + + + public function check($image, $isRemote = true) + { + $localPath = $image; + if ($isRemote) { + $response = $this->get($image)->send(); + if (!$response->isOk) { + throw new BadRequestHttpException(); + } + + $localPath = Yii::getAlias('@runtime/temp/upload/' . date('Ymd')); + if (!is_dir($localPath)) { + FileHelper::createDirectory($localPath); + } + $localPath .= '/' . Yii::$app->security->generateRandomString(32) . '.jpg'; + + $content = $response->getContent(); + + file_put_contents($localPath, $content); + } + + $response = $this->upload(static::API_SEND_CHECK . $this->accessToken, ['media', $localPath])->send(); + if ($isRemote) { + @unlink($localPath); + } + + if ($response->isOk) { + $content = json_decode($response->getContent(), 1); + if ($content['errcode'] == 0) { + return true; + } else { + return false; + } + } else { + throw new BadRequestHttpException($response->content); + } + } + +} \ No newline at end of file diff --git a/src/mini/seccheck/MsgCheck.php b/src/mini/seccheck/MsgCheck.php new file mode 100644 index 0000000..a5409d4 --- /dev/null +++ b/src/mini/seccheck/MsgCheck.php @@ -0,0 +1,52 @@ +accessToken = (new AccessToken(['conf' => $this->conf, 'httpClient' => $this->httpClient]))->getToken(); + } + + + public function check($content) + { + $response = $this->httpClient + ->createRequest() + ->setUrl(static::API_SEND_CHECK . $this->accessToken) + ->setFormat(Client::FORMAT_CURL) + ->setMethod('POST') + ->setContent(json_encode(['content' => $content], JSON_UNESCAPED_UNICODE)) + ->send(); + + if ($response->isOk) { + $content = json_decode($response->getContent(), 1); + + if ($content['errcode'] == 0) { + return true; + } else { + return false; + } + } else { + throw new BadRequestHttpException($response->content); + } + } +} \ No newline at end of file From 1f4161e0c3d8e968174d4959dea2bd5ec63463d5 Mon Sep 17 00:00:00 2001 From: liyifei <119422342@qq.com> Date: Thu, 9 Jan 2020 09:34:04 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Application.php | 1 + src/example/common.php | 14 +++++++++ src/example/subscribe.php | 25 ++++++++++++++++ src/mini/subscribe/Subscribe.php | 51 ++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 src/example/subscribe.php create mode 100644 src/mini/subscribe/Subscribe.php diff --git a/src/Application.php b/src/Application.php index 1cd7296..50feb90 100644 --- a/src/Application.php +++ b/src/Application.php @@ -77,6 +77,7 @@ class Application extends Component 'pay' => 'abei2017\wx\mini\payment\Pay', // 支付 'qrcode' => 'abei2017\wx\mini\qrcode\Qrcode', // 二维码&小程序码 'template' => 'abei2017\wx\mini\template\Template', // 模板消息 + 'subscribe' => 'abei2017\wx\mini\subscribe\Subscribe', // 订阅消息 'custom' => 'abei2017\wx\mini\custom\Customer', 'server' => 'abei2017\wx\mini\custom\Server', 'imgcheck' => 'abei2017\wx\mini\seccheck\ImgCheck', // 图片内容监测 diff --git a/src/example/common.php b/src/example/common.php index a0e06a2..312eb7f 100644 --- a/src/example/common.php +++ b/src/example/common.php @@ -20,9 +20,23 @@ 'class' => 'yii\caching\FileCache', 'cachePath' => '@runtime/cache' ], + 'log' => [ + 'traceLevel' => YII_DEBUG ? 3 : 0, + 'targets' => [ + [ + 'class' => 'yii\log\FileTarget', + 'levels' => ['info', 'error', 'warning'], +// 'categories' => ['yii\db\*'], + 'logVars' => [], + 'logFile' => '@runtime/log/app.log' + ], + ] + ] ] ]); + + $conf = file_get_contents('./config.txt'); $conf = json_decode($conf, 1); diff --git a/src/example/subscribe.php b/src/example/subscribe.php new file mode 100644 index 0000000..8879c4d --- /dev/null +++ b/src/example/subscribe.php @@ -0,0 +1,25 @@ +driver('mini.subscribe'); +$response = $driver->send('o_DtZ5PSuv51X2whblLf1CJoaPHk', 'NLBy_q8YAiF4V0TLssWEEHIAtSqypoiD9oRsPe0DkrU', '', [ + 'name1' => [ + 'value' => '李奕飞' + ], + 'thing2' => [ + 'value' => 'test' + ], + 'date3' => [ + 'value' => '2018-01-01', + ] +]); + +print_r($response); \ No newline at end of file diff --git a/src/mini/subscribe/Subscribe.php b/src/mini/subscribe/Subscribe.php new file mode 100644 index 0000000..5e0e599 --- /dev/null +++ b/src/mini/subscribe/Subscribe.php @@ -0,0 +1,51 @@ +accessToken = (new AccessToken(['conf' => $this->conf, 'httpClient' => $this->httpClient]))->getToken(); + } + + /** + * 发送订阅消息 + * + * @param $toUser + * @param $templateId + * @param $formId + * @param $data + * @param array $extra + */ + public function send($toUser, $templateId, $page, $data) + { + $params = [ + 'touser' => $toUser, + 'template_id' => $templateId, + 'page' => $page, + 'data' => $data, + 'access_token' => $this->accessToken + ]; + + $response = $this->post(self::API_SEND_SSB . $this->accessToken, $params)->setFormat(Client::FORMAT_JSON)->send(); + + return $response->getContent(); + } +} \ No newline at end of file From bde931ce5a2049dd4a8e5b6fa253580df9b6f942 Mon Sep 17 00:00:00 2001 From: LEEYIFIEI <119422342@qq.com> Date: Tue, 18 Feb 2020 18:50:14 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mini/seccheck/ImgCheck.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mini/seccheck/ImgCheck.php b/src/mini/seccheck/ImgCheck.php index 6318c17..ec6b729 100644 --- a/src/mini/seccheck/ImgCheck.php +++ b/src/mini/seccheck/ImgCheck.php @@ -21,6 +21,8 @@ class ImgCheck extends Driver private $accessToken = null; + private $_retries = 0; + public function init() { parent::init(); @@ -55,6 +57,14 @@ public function check($image, $isRemote = true) if ($response->isOk) { $content = json_decode($response->getContent(), 1); + + if ($content['errcode'] == 87015 && $this->_retries < 3) { + $this->_retries++; + return $this->check($image, $isRemote); + } else { + return true; + } + if ($content['errcode'] == 0) { return true; } else { From ab4e34dc502c9bdce343827967f4052ff4d66fd2 Mon Sep 17 00:00:00 2001 From: LEEYIFIEI <119422342@qq.com> Date: Wed, 8 Apr 2020 09:59:40 +0800 Subject: [PATCH 7/8] =?UTF-8?q?oauth=E5=A2=9E=E5=8A=A0scan=20qrcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/example/common.php | 4 ++++ src/example/oauth.php | 16 ++++++++++++++ src/mp/oauth/OAuth.php | 49 ++++++++++++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/example/oauth.php diff --git a/src/example/common.php b/src/example/common.php index 312eb7f..a3916bd 100644 --- a/src/example/common.php +++ b/src/example/common.php @@ -44,6 +44,10 @@ 'conf' => [ 'app_id' => $conf['appkey'], 'secret' => $conf['appsecret'], + 'oauth' => [ + 'scopes' => $conf['mp.qrcode.scopes'], + 'callback' => $conf['mp.qrcode.callback'] + ] ] ]); diff --git a/src/example/oauth.php b/src/example/oauth.php new file mode 100644 index 0000000..9a491ef --- /dev/null +++ b/src/example/oauth.php @@ -0,0 +1,16 @@ +driver('mp.oauth'); + +var_dump($driver->qrcode()); \ No newline at end of file diff --git a/src/mp/oauth/OAuth.php b/src/mp/oauth/OAuth.php index 7234aa2..f18bff1 100644 --- a/src/mp/oauth/OAuth.php +++ b/src/mp/oauth/OAuth.php @@ -22,8 +22,10 @@ * @author abei * @link http://nai8.me/yii2wx */ -class OAuth extends Driver { +class OAuth extends Driver +{ + const API_QRCODE_URL = "https://open.weixin.qq.com/connect/qrconnect"; const API_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize"; const API_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token"; const API_USER_INFO_URL = "https://api.weixin.qq.com/sns/userinfo"; @@ -44,11 +46,22 @@ class OAuth extends Driver { */ protected $refreshAccessTokenCacheKey = 'wx-oauth-refresh-access-token'; + /** + * @desc 跳转扫描二维码页面 + */ + public function qrcode() + { + $url = "https://open.weixin.qq.com/connect/qrconnect?appid={$this->conf['app_id']}&redirect_uri={$this->conf['oauth']['callback']}&response_type=code&scope={$this->conf['oauth']['scopes']}&state=STATE#wechat_redirect"; + return $url; + header("Location: {$url}"); + } + /** * 跳转到授权页面 */ - public function send(){ - $url = self::API_AUTHORIZE_URL."?appid={$this->conf['app_id']}&redirect_uri={$this->conf['oauth']['callback']}&response_type=code&scope={$this->conf['oauth']['scopes']}&state=STATE#wechat_redirect"; + public function send() + { + $url = self::API_AUTHORIZE_URL . "?appid={$this->conf['app_id']}&redirect_uri={$this->conf['oauth']['callback']}&response_type=code&scope={$this->conf['oauth']['scopes']}&state=STATE#wechat_redirect"; header("location:{$url}"); } @@ -58,22 +71,23 @@ public function send(){ * @return bool * @throws Exception */ - protected function initAccessToken(){ - if($this->accessToken){ + protected function initAccessToken() + { + if ($this->accessToken) { return $this->accessToken; } $code = $this->getCode(); - $url = self::API_ACCESS_TOKEN_URL."?appid={$this->conf['app_id']}&secret={$this->conf['secret']}&code={$code}&grant_type=authorization_code"; + $url = self::API_ACCESS_TOKEN_URL . "?appid={$this->conf['app_id']}&secret={$this->conf['secret']}&code={$code}&grant_type=authorization_code"; $response = $this->get($url)->send(); - if($response->isOk == false){ + if ($response->isOk == false) { throw new Exception(self::ERROR_NO_RESPONSE); } $response->setFormat(Client::FORMAT_JSON); $data = $response->getData(); - if(isset($data['errcode']) && $data['errcode'] != 0){ + if (isset($data['errcode']) && $data['errcode'] != 0) { throw new Exception($data['errmsg'], $data['errcode']); } @@ -87,8 +101,9 @@ protected function initAccessToken(){ * 获得web授权的access token和openId * @return bool */ - public function getOpenId(){ - if($this->openId){ + public function getOpenId() + { + if ($this->openId) { return $this->openId; } @@ -97,8 +112,9 @@ public function getOpenId(){ return $this->openId; } - protected function getCode(){ - if($this->code == false){ + protected function getCode() + { + if ($this->code == false) { $this->code = Yii::$app->request->get('code'); } @@ -111,17 +127,18 @@ protected function getCode(){ * @return mixed * @throws Exception */ - public function user(){ + public function user() + { $this->initAccessToken(); - $url = self::API_USER_INFO_URL."?access_token={$this->accessToken}&openid={$this->openId}&lang=zh_CN"; + $url = self::API_USER_INFO_URL . "?access_token={$this->accessToken}&openid={$this->openId}&lang=zh_CN"; $response = $this->get($url)->send(); - if($response->isOk == false){ + if ($response->isOk == false) { throw new Exception(self::ERROR_NO_RESPONSE); } $response->setFormat(Client::FORMAT_JSON); $data = $response->getData(); - if(isset($data['errcode']) && $data['errcode'] != 0){ + if (isset($data['errcode']) && $data['errcode'] != 0) { throw new Exception($data['errmsg'], $data['errcode']); } From 831799c57146bbe5a7a5d0e8a6179d57fff28c45 Mon Sep 17 00:00:00 2001 From: LEEYIFIEI <119422342@qq.com> Date: Wed, 8 Apr 2020 10:52:59 +0800 Subject: [PATCH 8/8] =?UTF-8?q?oauth=E5=A2=9E=E5=8A=A0scan=20qrcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mp/oauth/OAuth.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mp/oauth/OAuth.php b/src/mp/oauth/OAuth.php index f18bff1..7c76ad0 100644 --- a/src/mp/oauth/OAuth.php +++ b/src/mp/oauth/OAuth.php @@ -52,7 +52,6 @@ class OAuth extends Driver public function qrcode() { $url = "https://open.weixin.qq.com/connect/qrconnect?appid={$this->conf['app_id']}&redirect_uri={$this->conf['oauth']['callback']}&response_type=code&scope={$this->conf['oauth']['scopes']}&state=STATE#wechat_redirect"; - return $url; header("Location: {$url}"); }