Showing
3 changed files
with
194 additions
and
4 deletions
... | @@ -50,9 +50,7 @@ windows的cms工具,可以使用ConEmu或者cmder工具 | ... | @@ -50,9 +50,7 @@ windows的cms工具,可以使用ConEmu或者cmder工具 |
50 | 50 | ||
51 | 开发工具下载: | 51 | 开发工具下载: |
52 | 52 | ||
53 | -phpstorm : [下载链接](https://www.jetbrains.com/phpstorm/download/#section=windows) | 53 | +phpstorm : [下载链接](https://www.jetbrains.com/phpstorm/download/#section=windows) 注:phpstorm64位版本依赖于JRE |
54 | - | ||
55 | -? 注:phpstorm64位版本依赖于JRE | ||
56 | 54 | ||
57 | phpstorm的注册激活 : [参考](http://idea.lanyus.com/) | 55 | phpstorm的注册激活 : [参考](http://idea.lanyus.com/) |
58 | 56 | ||
... | @@ -66,6 +64,8 @@ Conemu下载 [下载链接](http://conemu.github.io/en/Downloads.html) | ... | @@ -66,6 +64,8 @@ Conemu下载 [下载链接](http://conemu.github.io/en/Downloads.html) |
66 | 64 | ||
67 | 65 | ||
68 | 66 | ||
67 | + | ||
68 | + | ||
69 | ### 5. 关于PHP默认编码规范 | 69 | ### 5. 关于PHP默认编码规范 |
70 | 70 | ||
71 | * [5.1 PHP语言编码规范 v1.0](php_rule.md) | 71 | * [5.1 PHP语言编码规范 v1.0](php_rule.md) |
... | @@ -73,21 +73,27 @@ Conemu下载 [下载链接](http://conemu.github.io/en/Downloads.html) | ... | @@ -73,21 +73,27 @@ Conemu下载 [下载链接](http://conemu.github.io/en/Downloads.html) |
73 | 73 | ||
74 | 74 | ||
75 | 75 | ||
76 | + | ||
77 | + | ||
76 | ### 6. 数据库规范 | 78 | ### 6. 数据库规范 |
77 | 79 | ||
78 | * 6.1 [数据库规范](database.md) | 80 | * 6.1 [数据库规范](database.md) |
79 | 81 | ||
80 | 82 | ||
81 | 83 | ||
84 | + | ||
85 | + | ||
82 | ### 7. GIT代码管理规范 | 86 | ### 7. GIT代码管理规范 |
83 | 87 | ||
84 | * 7.1 [GIT Flow规范](git_flow.md) | 88 | * 7.1 [GIT Flow规范](git_flow.md) |
85 | 89 | ||
86 | 90 | ||
87 | 91 | ||
92 | + | ||
93 | + | ||
88 | ### 8. 项目开发流程规范 | 94 | ### 8. 项目开发流程规范 |
89 | 95 | ||
90 | -* 8.1 [产品设计规范]() | 96 | +* 8.1 [文档规范]() |
91 | * 8.2 [项目开发规范]() | 97 | * 8.2 [项目开发规范]() |
92 | * 8.3 [测试规范]() | 98 | * 8.3 [测试规范]() |
93 | * 8.4 [生产部署规范]() | 99 | * 8.4 [生产部署规范]() | ... | ... |
Docs/Rules/PHP/Samples/my_class_sample.md
0 → 100644
1 | +### PHP自定义类示例(Weixin消息解析类) | ||
2 | + | ||
3 | + | ||
4 | + | ||
5 | +```php | ||
6 | +/** | ||
7 | + * Created by Qingger. | ||
8 | + * User: jsspf | ||
9 | + * Date: 2017/3/24 | ||
10 | + * Time: 10:50 | ||
11 | + */ | ||
12 | + | ||
13 | +namespace App\Service; | ||
14 | + | ||
15 | +use App\Exception\TPException; | ||
16 | +use App\Library\VarDefines\GlobalErrCode; | ||
17 | + | ||
18 | +/** | ||
19 | + * 微信公众号消息的接收与回复 | ||
20 | + * @desc : 消息加解密指引参考 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&lang=zh_CN | ||
21 | + * Class WXMPEventMessageParser | ||
22 | + * @package App\Services\WeixinFunc | ||
23 | + */ | ||
24 | +class WeixinMPEventMessageParser extends WeixinBaseFuncService | ||
25 | +{ | ||
26 | + | ||
27 | + /** | ||
28 | + * @var object | ||
29 | + * 接收消息的消息体结构 (text | image | voice | video | shortvideo | location | link) | ||
30 | + */ | ||
31 | + private $_messageReceiveBody = null; | ||
32 | + | ||
33 | + /** | ||
34 | + * @var string | ||
35 | + * 接收消息的发送方帐号 | ||
36 | + */ | ||
37 | + private $_messageReceiveFrom = null; | ||
38 | + | ||
39 | + /** | ||
40 | + * @var string | ||
41 | + * 接收消息的接收方帐号 | ||
42 | + */ | ||
43 | + private $_messageReceiveTo = null; | ||
44 | + | ||
45 | + /** | ||
46 | + * @var string | ||
47 | + * 接收消息的消息体类型 (text | image | voice | video | shortvideo | location | link) | ||
48 | + */ | ||
49 | + private $_messageReceiveType = null; | ||
50 | + | ||
51 | + | ||
52 | + /** | ||
53 | + * @var string | ||
54 | + * 接收消息时,Request请求中的nonce信息 | ||
55 | + */ | ||
56 | + private $_messageNonce = ''; | ||
57 | + | ||
58 | + /** | ||
59 | + * @var WXBizMsgCrypt | ||
60 | + * 微信消息体加解密对象 | ||
61 | + */ | ||
62 | + private $_wxBizMsgCrypt = null; | ||
63 | + | ||
64 | + /** | ||
65 | + * @var array | ||
66 | + * 公众号消息回复的模板 | ||
67 | + */ | ||
68 | + private $_replyMessageTemplate = [ | ||
69 | + // 文本消息的回复模板 | ||
70 | + 'text' => "<xml> | ||
71 | + <ToUserName><![CDATA[%s]]></ToUserName> | ||
72 | + <FromUserName><![CDATA[%s]]></FromUserName> | ||
73 | + <CreateTime>%s</CreateTime> | ||
74 | + <MsgType><![CDATA[text]]></MsgType> | ||
75 | + <Content><![CDATA[%s]]></Content> | ||
76 | + </xml>", | ||
77 | + | ||
78 | + // 图片消息的回复模板 | ||
79 | + 'image' => "<xml> | ||
80 | + <ToUserName><![CDATA[%s]]></ToUserName> | ||
81 | + <FromUserName><![CDATA[%s]]></FromUserName> | ||
82 | + <CreateTime>%s</CreateTime> | ||
83 | + <MsgType><![CDATA[image]]></MsgType> | ||
84 | + <Image><MediaId><![CDATA[%s]]></MediaId></Image> | ||
85 | + </xml>", | ||
86 | + ]; | ||
87 | + | ||
88 | + | ||
89 | + public function __construct($tpSuiteName,$messageNonce='') | ||
90 | + { | ||
91 | + parent::__construct(); | ||
92 | + $this->_messageNonce = $messageNonce; | ||
93 | + $this->_wxBizMsgCrypt = new WXBizMsgCrypt( | ||
94 | + $this->getWxTpConfigParser()->getConfigToken($tpSuiteName), | ||
95 | + $this->getWxTpConfigParser()->getConfigEncodingAesKey($tpSuiteName), | ||
96 | + $this->getWxTpConfigParser()->getConfigId($tpSuiteName) | ||
97 | + ); | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * 对消息体进行微信的加密 | ||
102 | + * @param $replyMsgStr | ||
103 | + * @return string | ||
104 | + */ | ||
105 | + private function _encryptMessage($replyMsgStr) { | ||
106 | + $replyMessageEncrypt = ''; | ||
107 | + $this->_wxBizMsgCrypt->encryptMsg($replyMsgStr,time(),$this->_messageNonce,$replyMessageEncrypt); | ||
108 | + return $replyMessageEncrypt; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * 生成文本消息的回复结构 | ||
113 | + * @param $content | ||
114 | + * @return string | ||
115 | + */ | ||
116 | + public function textMessageReply($content) { | ||
117 | + $replyMessageType = 'text'; | ||
118 | + $replyMsgStr = sprintf($this->_replyMessageTemplate[$replyMessageType], | ||
119 | + $this->_messageReceiveFrom, | ||
120 | + $this->_messageReceiveTo, | ||
121 | + time(), | ||
122 | + $content); | ||
123 | + return $this->_encryptMessage($replyMsgStr); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * 生成图片消息的回复 | ||
128 | + * @param $imageMediaId | ||
129 | + * @return string | ||
130 | + */ | ||
131 | + public function imageMessageReply($imageMediaId) { | ||
132 | + $replyMessageType = 'image'; | ||
133 | + $replyMsgStr = sprintf($this->_replyMessageTemplate[$replyMessageType], | ||
134 | + $this->_messageReceiveFrom, | ||
135 | + $this->_messageReceiveTo, | ||
136 | + time(), | ||
137 | + $imageMediaId); | ||
138 | + return $this->_encryptMessage($replyMsgStr); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Todo : 需要实现,使用XML对象操作字符串模板 | ||
143 | + * 生成音乐消息的回复 | ||
144 | + * @param array $musicInfo | ||
145 | + * [ | ||
146 | + * 'title' : 标题 / 可选 | ||
147 | + * 'description' : 描述 / 可选 | ||
148 | + * 'musicURL' : 音乐链接 / 可选 | ||
149 | + * 'hqMusicUrl' : 高质量音乐链接,WIFI环境优先使用该链接播放音乐 / 可选 | ||
150 | + * 'ThumbMediaId' : 缩略图的媒体id,通过素材管理接口上传多媒体文件,得到的id / 可选 | ||
151 | + * ] | ||
152 | + * @throws TPException | ||
153 | + * @return string | ||
154 | + */ | ||
155 | + public function musicMessageReply(array $musicInfo) { | ||
156 | + throw new TPException('Music Message Reply Not Support',GlobalErrCode::ERR_FUNCTION_NOT_IMPLEMENT); | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * 解析Weixin Message消息,并根据相应的消息,进行回复 | ||
161 | + * @desc 具体解密参考:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318479&lang=zh_CN | ||
162 | + * @param $messageEventObj | ||
163 | + * @param Closure $doEvent | ||
164 | + * @return mixed | ||
165 | + * @throws TPException | ||
166 | + */ | ||
167 | + public function parseEvent($messageEventObj,Closure $doEvent) { | ||
168 | + if(isset($messageEventObj->MsgType)) { | ||
169 | + $this->_messageReceiveBody = $messageEventObj; | ||
170 | + $this->_messageReceiveFrom = isset($messageEventObj->FromUserName)?$messageEventObj->FromUserName:null; | ||
171 | + $this->_messageReceiveTo = isset($messageEventObj->ToUserName)?$messageEventObj->ToUserName:null; | ||
172 | + $this->_messageReceiveType = $messageEventObj->MsgType; | ||
173 | + | ||
174 | + $messageReply = $doEvent($messageEventObj); | ||
175 | + | ||
176 | + return $messageReply; | ||
177 | + } else { | ||
178 | + throw new TPException('MP Message Body Parse Error',GlobalErrCode::ERR_WEIXIN_MESSAGE_INFO_ERROR); | ||
179 | + } | ||
180 | + | ||
181 | + | ||
182 | +} | ||
183 | +``` | ||
184 | + |
Docs/Rules/PHP/php_rule.md
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment