I transplanted a piece of code from thinkphp3.1 to thinkphp3.2, and then there was such an error during the adjustment, so I couldn't find many of them. {Code ...} the valid method in ApiWechat is as follows: {code ...} what is the problem? I transplanted a piece of code from thinkphp 3.1 to thinkphp 3.2. Then, when I adjusted the code, I found this error and found a lot of problems.
Public function init () {$ config = M ("Wxconfig")-> where (array ("id" => "1")-> find (); $ options = array ('Token' => $ config ["token"], // enter your set key 'enabledingaeskey' => $ config ["encodingaeskey"], // enter the encryption EncodingAESKey 'appid '=> $ config ["appid"], // enter the app id 'appsecret' => $ config ["appsecret"] of the Advanced Call function, // enter the key of the Advanced Call function ); $ weObj = A ('api/Wechat ($ options) '); return $ weObj;} public function index () {$ weObj = $ this-> init (); $ weObj-> valid ();
The valid method in Api/Wechat is as follows:
/*** For weixin server validation * @ param bool $ return whether to return */public function valid ($ return = false) {$ encryptStr = ""; if ($ _ SERVER ['request _ method'] = "POST") {$ postStr = file_get_contents ("php: // input"); $ array = (array) simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ this-> encrypt_type = isset ($ _ GET ["encrypt_type"])? $ _ GET ["encrypt_type"]: ''; if ($ this-> encrypt_type = 'aes ') {// aes encryption $ this-> log ($ postStr ); $ encryptStr = $ array ['enabled']; $ pc = new Prpcrypt ($ this-> encodingAesKey); $ array = $ pc-> decrypt ($ encryptStr, $ this-> appid); if (! Isset ($ array [0]) | ($ array [0]! = 0) {if (! $ Return) {die ('crypt error! ');} Else {return false; }}$ this-> postxml = $ array [1]; if (! $ This-> appid) $ this-> appid = $ array [2]; // for subscription numbers without appid.} Else {$ this-> postxml = $ postStr;} elseif (isset ($ _ GET ["echostr"]) {$ echoStr = $ _ GET ["echostr"]; if ($ return) {if ($ this-> checkSignature () return $ echoStr; else return false ;} else {if ($ this-> checkSignature () die ($ echoStr); else die ('no access') ;}} if (! $ This-> checkSignature ($ encryptStr) {if ($ return) return false; else die ('no access');} return true ;}
What's the problem? TAT
Reply content:
I transplanted a piece of code from thinkphp 3.1 to thinkphp 3.2, and then there was such an error during the adjustment, and I couldn't find it after finding a lot.
Public function init () {$ config = M ("Wxconfig")-> where (array ("id" => "1")-> find (); $ options = array ('Token' => $ config ["token"], // enter your set key 'enabledingaeskey' => $ config ["encodingaeskey"], // enter the encryption EncodingAESKey 'appid '=> $ config ["appid"], // enter the app id 'appsecret' => $ config ["appsecret"] of the Advanced Call function, // enter the key of the Advanced Call function ); $ weObj = A ('api/Wechat ($ options) '); return $ weObj;} public function index () {$ weObj = $ this-> init (); $ weObj-> valid ();
The valid method in Api/Wechat is as follows:
/*** For weixin server validation * @ param bool $ return whether to return */public function valid ($ return = false) {$ encryptStr = ""; if ($ _ SERVER ['request _ method'] = "POST") {$ postStr = file_get_contents ("php: // input"); $ array = (array) simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ this-> encrypt_type = isset ($ _ GET ["encrypt_type"])? $ _ GET ["encrypt_type"]: ''; if ($ this-> encrypt_type = 'aes ') {// aes encryption $ this-> log ($ postStr ); $ encryptStr = $ array ['enabled']; $ pc = new Prpcrypt ($ this-> encodingAesKey); $ array = $ pc-> decrypt ($ encryptStr, $ this-> appid); if (! Isset ($ array [0]) | ($ array [0]! = 0) {if (! $ Return) {die ('crypt error! ');} Else {return false; }}$ this-> postxml = $ array [1]; if (! $ This-> appid) $ this-> appid = $ array [2]; // for subscription numbers without appid.} Else {$ this-> postxml = $ postStr;} elseif (isset ($ _ GET ["echostr"]) {$ echoStr = $ _ GET ["echostr"]; if ($ return) {if ($ this-> checkSignature () return $ echoStr; else return false ;} else {if ($ this-> checkSignature () die ($ echoStr); else die ('no access') ;}} if (! $ This-> checkSignature ($ encryptStr) {if ($ return) return false; else die ('no access');} return true ;}
What's the problem? TAT
$ WeObj = A ('api/Wechat ($ options )');
Isn't Thinkphp A called like this?
This indicates that the current version of the TP init method does not return an object in your code, but returns a Boolean value, which may be false;
Follow up the method of version 3.2: