Introduction to the set framework for writing PHP extensions using Zephir
The collection framework developed by Zephir can be easily integrated into your PHP. After a simple test.
Of course, there are still a lot of functions that are not complete and implemented, as well as lack of documentation. I will extract 1.1 points of time for improvement.
Install Linux
Install Environment dependency
#Ubuntu sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev#Fedora sudo yum install php-devel php-mysqlnd gcc libtool#RHEL sudo yum install php-devel php-mysql gcc libtool#Suse yast2 -i php5-pear php5-devel php5-mysql gcc
Install
git clone https://git.coding.net/widuu/wechat.git cd wechat/ext && ./install
Windows
Php5.6 and php5.5 have been compiled directly. you can click the address below to download them.
DLL List |
Python 5.6 |
5.6 Non Thread Safe (CNT) x86 5.6 Thread Safe (TS) x86 5.6 Non Thread Safe (ETS) x64 5.6 Thread Safe (TS) x64 |
Python 5.5 |
5.5 Non Thread Safe (CNT) x86 5.5 Thread Safe (TS) x86 5.5 Non Thread Safe (ETS) x64 5.5 Thread Safe (TS) x64 |
|
Contributing
Login https://coding.net or https://github.com
Repository address distribution:
Coding repository: https://coding.net/u/widuu/p/wechat/git
Github warehouse: http://github.com/widuu/wechat
Create your feature Branch (git checkout-B my-new-feature)
Submit your changes (git commit-am 'addded some feature ')
Submit your change record to the remote git repository (git push origin my-new-feature)
Then, go to the my-new-feature branch of the git remote repository on the coding website to initiate a Pull Request.Contact Info
Email: admin # widu.com <# Replace with @>
Blog: http://www.widuu.com
Weaver: http://weibo.com/widuu
Core code
Wechat. zep
Namespace Wechat; class Wechat extends Wechatabstract {/*** sender id */protected _ tousername {get, set};/*** wechat id */protected _ fromusername {get, set};/*** event type */protected _ msgtype {get, set};/*** event */protected _ event {get, set }; /*** creation time */protected _ createtime {get, set};/*** text message content */protected _ content {get, set }; /*** message id */protected _ msgid {get, set};/*** image link */protected _ picurl {get, set }; /*** media id */protected _ mediaid {get, set};/*** speech format */protected _ format {get, set }; /*** media id of the thumbnail */protected _ thumbmediaid {get, set};/*** Geographic location dimension */protected _ location_x {get, set }; /*** geographic longitude */protected _ location_y {get, set};/*** map zoom size */protected _ scale {get, set }; /*** Geographic location information */protected _ label {get, set};/*** message title */protected _ title {get, set }; /*** message description */protected _ description {get, set};/*** message link */protected _ url {get, set }; /*** token url */const TOKEN_URL =" https://api.weixin.qq.com/cgi-bin/token ? ";/*** User URL */const USER_URL =" https://api.weixin.qq.com/cgi-bin/user/ ";/*** Menu URL */const MENU_URL =" https://api.weixin.qq.com/cgi-bin/menu/ ";/*** Receive POST information * @ author widuu */public function getRequest () {if this-> isPost () {var key, value; let this-> _ request_data = this-> getInfo (true); if this-> _ debug {if empty this-> _ request_data {this-> log ("[ERROR ". date ("Y-m-d H: I: s", time ()). "] Request Data NULL \ r \ n") ;}}; if! Empty this-> _ request_data {for key, value in this-> _ request_data {let key = "_". strtolower (key); if isset this-> {key} {let this-> {key} = value ;}} return this-> _ request_data ;}} else {return false ;}}/*** return message method * @ param string type * @ param (array | string) type * @ return boolean * @ author widuu */public function response (string! Type = null, info) {if empty this-> _ request_data {return false;} var tpl; let tpl = this-> getTpl (type, info ); if this-> _ debug {if empty tpl {this-> log ("[ERROR ". date ("Y-m-d H: I: s", time ()). "] Get Response XML Type Error \ r \ n") ;}}; echo tpl ;}/ *** subscribe event * @ author widuu */public function subscribe (string! Type = "text", info) {if empty this-> _ request_data {return false;} if (this-> _ event = "subscribe ") {this-> response (type, info); return ;}} /*** get Token * @ param string appid * @ param string secret * @ return array * @ author widuu */public function getToken (string! Appid = "", string! Secret = "") {if (empty appid | empty secret) {throw new Exception ("getToken Method Parameter does not allow nulls", 4001) ;}; var tokenUrl, urlQurey, result; let urlQurey = ["grant_type": "client_credential", "appid": appid, "secret": secret]; let tokenUrl = Wechat: TOKEN_URL.http_build_query (urlQurey ); let result = this-> httpGet (tokenUrl); return json_decode (result, true);}/*** get user information ** @ param string Type * @ param string token * @ param string openid * @ return array * @ author widuu */public function getUser (string! Type = null, string! Token = "", string openid = "") {if empty token | empty type {throw new Exception ("Parameter does not allow nulls", 4002);} var url, param, result; switch (type) {case "userinfo": let param = ["access_token": token, "openid": openid, "lang": "zh_CN"]; let url = Wechat: USER_URL. "info? ". Http_build_query (param); let result = this-> httpGet (url); break; case "userlist": let param = ["access_token": token, "next_openid": openid]; let url = Wechat: USER_URL. "get? ". Http_build_query (param); let result = this-> httpGet (url); break; default: return false;} return json_decode (result, true );} /*** set user remarks ** @ param string token * @ param string openid * @ param string remarke * @ return array * @ author widuu */public function setRemark (string! Token = null, string! Openid = null, string! Remarke = null)-> boolean {var remarkUrl, postInfo, result; let remarkUrl = Wechat: USER_URL. "info/updateremark? Access_token = ". token; let postInfo = [" openid ": openid," remark ": remarke]; let result = this-> httpPost (remarkUrl, postInfo); if! Result {return false;} return json_decode (result, true);}/*** get custom Menu * @ author widuu */public function Menu (string! Type = null, string! Token = null, array info = null) {var menu_url, result; switch (type) {case "get": let menu_url = Wechat: MENU_URL. "get? Access_token = ". token; let result = this-> httpGet (menu_url); break; case" delete ": let menu_url = Wechat: MENU_URL." delete? Access_token = ". token; let result = this-> httpGet (menu_url); break; case" create ": if typeof info! = "Array" | empty info {throw new Exception ("create param error", 4005);} let menu_url = Wechat: MENU_URL. "create? Access_token = ". token; let result = this-> httpPost (menu_url, info); default: return false;} if! Empty result {return json_decode (result, true);} else {throw new Exception ("Response Error", 4003 );}} /*** method for getting variables * @ param string name * @ return boolean | string * @ author widuu */public function _ get (string! Name) {let name = "_". name; if isset this-> {name} {return this-> {name};} return false ;} /*** variable setting method * @ param string name * @ param value * @ return boolean * @ author widuu */public function _ set (string! Name, value)-> boolean {let name = "_". name; if isset this-> {name} {let this-> {name} = value; return true;} return false ;} /*** variable setting method * @ param string name * @ param value * @ return boolean * @ author widuu */protected function getTpl (string! Type = null, info) {// organize xml var tpl; let tpl ="
".this->_fromusername."
".this->_tousername."
". Time ()."
".type."
"; Switch (type) {case" text ": let tpl. ="
".info."
"; Break; case" image ": let tpl. ="
".info."
"; Break; case" voice ": let tpl. ="
".info."
"; Break; case" video ": let tpl. ="
".info."
<! [CDATA [title]>
description
"; Break; case" music ": if typeof info! = "Array" {return false;} let tpl. ="
<! [CDATA [". info [" title "]."]>
".info["description"]."
".info["musicurl"]."
".info["hqmusicurl"]."
".info["mediaid"]."
"; Break; case" news ": if typeof info! = "Array" {return false;} var num; if isset info ["title"] {let num = 1;} else {let num = count (info );} let tpl. = "". num."". This-> getNews (info ).""; Break; default: return false;} let tpl. ="
"; Return tpl;}/*** method for determining the request * @ author widuu */private function isPost ()-> boolean {if strtolower (_ SERVER [" REQUEST_METHOD "]) = "post" {return true;} return false;}/*** get news * @ author widuu */private function getNews (array! Info) {var value, tpl = ""; if isset info ["title"] {let tpl. ="
<! [CDATA [". info [" title "]."]>
".info["description"]."
".info["picurl"]."
".info["url"]."
";} Else {for _, value in info {let tpl. ="
<! [CDATA [". value [" title "]."]>
".value["description"]."
".value["picurl"]."
".value["url"]."
";}} Return tpl;}/*** verify * @ author widuu */static public function valid (string! Token = null) {var signature, timestamp, nonce, tmpArr, tmpStr, echoStr; let signature = _ GET ["signature"]; let timestamp = _ GET ["timestamp"]; let nonce = _ GET ["nonce"]; let echoStr = _ GET ["echostr"]; let tmpArr = [token, timestamp, nonce]; sort (tmpArr, SORT_STRING ); let tmpStr = implode ("", tmpArr); let tmpStr = sha1 (tmpStr); if tmpStr = signature {echo echoStr;} else {return false ;}}/*** Set the URL expiration time * @ author widuu */public static function setTimeout (int! Timeout = 1) {globals_set ("curl_timeout", timeout); return true ;} /*** http get method * @ param string url * @ author widuu */protected function httpGet (string! Url = "") {var curlHandle, content, timeout; let timeout = globals_get ("curl_timeout"); let curlHandle = curl_init (); curl_setopt (curlHandle, CURLOPT_URL, url ); curl_setopt (curlHandle, handle, 1); curl_setopt (curlHandle, handle, false); curl_setopt (curlHandle, handle, false); curl_setopt (curlHandle, CURLOPT_TIMEOUT, timeout); let content = Curl_exec (curlHandle); curl_close (curlHandle); return content ;} /*** http post method * @ param string url * @ param array info * @ author widuu */protected function httpPost (string! Url = null, array info) {var curlHandle, content, timeout; if typeof info! = "Array" {throw new Exception ("infomation must be type array", 4004);} let timeout = globals_get ("curl_timeout"); let curlHandle = curl_init (url ); curl_setopt (curlHandle, CURLOPT_HEADER, 0); curl_setopt (curlHandle, iterator, 1); curl_setopt (curlHandle, CURLOPT_POST, 1); curl_setopt (curlHandle, iterator, iterator (info, curl_setopt (curlHandle, handle, false); curl_setopt (curlHandle, handle, false); curl_setopt (curlHandle, CURLOPT_TIMEOUT, timeout); let content = curl_exec (curlHandle ); curl_close (curlHandle); return content ;}