AopClient.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. <?php
  2. require_once 'AopEncrypt.php';
  3. require_once 'EncryptParseItem.php';
  4. require_once 'EncryptResponseData.php';
  5. require_once 'SignData.php';
  6. require_once 'AlipayConfig.php';
  7. class AopClient
  8. {
  9. //应用ID
  10. public $appId;
  11. //私钥文件路径
  12. public $rsaPrivateKeyFilePath;
  13. //私钥值
  14. public $rsaPrivateKey;
  15. //网关
  16. public $gatewayUrl = "https://openapi.alipay.com/gateway.do";
  17. //返回数据格式
  18. public $format = "json";
  19. //api版本
  20. public $apiVersion = "1.0";
  21. // 表单提交字符集编码
  22. public $postCharset = "UTF-8";
  23. //使用文件读取文件格式,请只传递该值
  24. public $alipayPublicKey = null;
  25. //使用读取字符串格式,请只传递该值
  26. public $alipayrsaPublicKey;
  27. public $debugInfo = false;
  28. private $fileCharset = "UTF-8";
  29. private $RESPONSE_SUFFIX = "_response";
  30. private $ERROR_RESPONSE = "error_response";
  31. private $SIGN_NODE_NAME = "sign";
  32. //加密XML节点名称
  33. private $ENCRYPT_XML_NODE_NAME = "response_encrypted";
  34. private $needEncrypt = false;
  35. //签名类型
  36. public $signType = "RSA";
  37. //加密密钥和类型
  38. public $encryptKey;
  39. public $encryptType = "AES";
  40. private $targetServiceUrl = "";
  41. protected $alipaySdkVersion = "alipay-sdk-PHP-4.11.14.ALL";
  42. function __construct() {
  43. //根据参数个数和参数类型 来做相应的判断
  44. if(func_num_args()==1 && func_get_arg(0) instanceof AlipayConfig){
  45. $config = func_get_arg(0);
  46. $this->appId = $config->getAppId();
  47. $this->format = $config->getFormat();
  48. $this->gatewayUrl = $config->getServerUrl();
  49. $this->signType = $config->getSignType();
  50. $this->postCharset = $config->getCharset();
  51. $this->rsaPrivateKey = $config->getPrivateKey();
  52. $this->alipayrsaPublicKey = $config->getAlipayPublicKey();
  53. }
  54. }
  55. public function generateSign($params, $signType = "RSA")
  56. {
  57. $params = array_filter($params);
  58. $params['sign_type'] = $signType;
  59. return $this->sign($this->getSignContent($params), $signType);
  60. }
  61. public function rsaSign($params, $signType = "RSA")
  62. {
  63. return $this->sign($this->getSignContent($params), $signType);
  64. }
  65. public function getSignContent($params)
  66. {
  67. ksort($params);
  68. unset($params['sign']);
  69. $stringToBeSigned = "";
  70. $i = 0;
  71. foreach ($params as $k => $v) {
  72. if ("@" != substr($v, 0, 1)) {
  73. // 转换成目标字符集
  74. $v = $this->characet($v, $this->postCharset);
  75. if ($i == 0) {
  76. $stringToBeSigned .= "$k" . "=" . "$v";
  77. } else {
  78. $stringToBeSigned .= "&" . "$k" . "=" . "$v";
  79. }
  80. $i++;
  81. }
  82. }
  83. unset ($k, $v);
  84. return $stringToBeSigned;
  85. }
  86. //此方法对value做urlencode
  87. public function getSignContentUrlencode($params)
  88. {
  89. ksort($params);
  90. $stringToBeSigned = "";
  91. $i = 0;
  92. foreach ($params as $k => $v) {
  93. if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
  94. // 转换成目标字符集
  95. $v = $this->characet($v, $this->postCharset);
  96. if ($i == 0) {
  97. $stringToBeSigned .= "$k" . "=" . urlencode($v);
  98. } else {
  99. $stringToBeSigned .= "&" . "$k" . "=" . urlencode($v);
  100. }
  101. $i++;
  102. }
  103. }
  104. unset ($k, $v);
  105. return $stringToBeSigned;
  106. }
  107. protected function sign($data, $signType = "RSA")
  108. {
  109. if ($this->checkEmpty($this->rsaPrivateKeyFilePath)) {
  110. $priKey = $this->rsaPrivateKey;
  111. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  112. wordwrap($priKey, 64, "\n", true) .
  113. "\n-----END RSA PRIVATE KEY-----";
  114. } else {
  115. $priKey = file_get_contents($this->rsaPrivateKeyFilePath);
  116. $res = openssl_get_privatekey($priKey);
  117. }
  118. ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  119. if ("RSA2" == $signType) {
  120. openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
  121. } else {
  122. openssl_sign($data, $sign, $res);
  123. }
  124. if (!$this->checkEmpty($this->rsaPrivateKeyFilePath)) {
  125. openssl_free_key($res);
  126. }
  127. $sign = base64_encode($sign);
  128. return $sign;
  129. }
  130. /**
  131. * RSA单独签名方法,未做字符串处理,字符串处理见getSignContent()
  132. * @param $data 待签名字符串
  133. * @param $privatekey 商户私钥,根据keyfromfile来判断是读取字符串还是读取文件,false:填写私钥字符串去回车和空格 true:填写私钥文件路径
  134. * @param $signType 签名方式,RSA:SHA1 RSA2:SHA256
  135. * @param $keyfromfile 私钥获取方式,读取字符串还是读文件
  136. * @return string
  137. */
  138. public function alonersaSign($data, $privatekey, $signType = "RSA", $keyfromfile = false)
  139. {
  140. if (!$keyfromfile) {
  141. $priKey = $privatekey;
  142. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  143. wordwrap($priKey, 64, "\n", true) .
  144. "\n-----END RSA PRIVATE KEY-----";
  145. } else {
  146. $priKey = file_get_contents($privatekey);
  147. $res = openssl_get_privatekey($priKey);
  148. }
  149. ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  150. if ("RSA2" == $signType) {
  151. openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
  152. } else {
  153. openssl_sign($data, $sign, $res);
  154. }
  155. if ($keyfromfile) {
  156. openssl_free_key($res);
  157. }
  158. $sign = base64_encode($sign);
  159. return $sign;
  160. }
  161. protected function curl($url, $postFields = null)
  162. {
  163. $ch = curl_init();
  164. curl_setopt($ch, CURLOPT_URL, $url);
  165. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  166. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  167. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  168. $postBodyString = "";
  169. $encodeArray = Array();
  170. $postMultipart = false;
  171. if (is_array($postFields) && 0 < count($postFields)) {
  172. foreach ($postFields as $k => $v) {
  173. if ("@" != substr($v, 0, 1)) //判断是不是文件上传
  174. {
  175. $postBodyString .= "$k=" . urlencode($this->characet($v, $this->postCharset)) . "&";
  176. $encodeArray[$k] = $this->characet($v, $this->postCharset);
  177. } else //文件上传用multipart/form-data,否则用www-form-urlencoded
  178. {
  179. $postMultipart = true;
  180. $encodeArray[$k] = new \CURLFile(substr($v, 1));
  181. }
  182. }
  183. unset ($k, $v);
  184. curl_setopt($ch, CURLOPT_POST, true);
  185. if ($postMultipart) {
  186. curl_setopt($ch, CURLOPT_POSTFIELDS, $encodeArray);
  187. } else {
  188. curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));
  189. }
  190. }
  191. if (!$postMultipart) {
  192. $headers = array('content-type: application/x-www-form-urlencoded;charset=' . $this->postCharset);
  193. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  194. }
  195. $reponse = curl_exec($ch);
  196. if (curl_errno($ch)) {
  197. throw new \Exception(curl_error($ch), 0);
  198. } else {
  199. $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  200. if (200 !== $httpStatusCode) {
  201. throw new \Exception($reponse, $httpStatusCode);
  202. }
  203. }
  204. curl_close($ch);
  205. return $reponse;
  206. }
  207. protected function getMillisecond()
  208. {
  209. list($s1, $s2) = explode(' ', microtime());
  210. return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
  211. }
  212. protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
  213. {
  214. $logData = array(
  215. date("Y-m-d H:i:s"),
  216. $apiName,
  217. $this->appId,
  218. PHP_OS,
  219. $this->alipaySdkVersion,
  220. $requestUrl,
  221. $errorCode,
  222. str_replace("\n", "", $responseTxt)
  223. );
  224. echo json_encode($logData);
  225. }
  226. /**
  227. * 生成用于调用收银台SDK的字符串
  228. * @param $request SDK接口的请求参数对象
  229. * @param $appAuthToken 三方应用授权token
  230. * @return string
  231. */
  232. public function sdkExecute($request, $appAuthToken = null)
  233. {
  234. $this->setupCharsets($request);
  235. $params['app_id'] = $this->appId;
  236. $params['method'] = $request->getApiMethodName();
  237. $params['format'] = $this->format;
  238. $params['sign_type'] = $this->signType;
  239. $params['timestamp'] = date("Y-m-d H:i:s");
  240. $params['alipay_sdk'] = $this->alipaySdkVersion;
  241. $params['charset'] = $this->postCharset;
  242. $version = $request->getApiVersion();
  243. $params['version'] = $this->checkEmpty($version) ? $this->apiVersion : $version;
  244. if ($notify_url = $request->getNotifyUrl()) {
  245. $params['notify_url'] = $notify_url;
  246. }
  247. $params['app_auth_token'] = $appAuthToken;
  248. $dict = $request->getApiParas();
  249. $params['biz_content'] = $dict['biz_content'];
  250. ksort($params);
  251. $params['sign'] = $this->generateSign($params, $this->signType);
  252. foreach ($params as &$value) {
  253. $value = $this->characet($value, $params['charset']);
  254. }
  255. return http_build_query($params);
  256. }
  257. /**
  258. * 页面提交执行方法
  259. * @param $request 跳转类接口的request
  260. * @param string $httpmethod 提交方式,两个值可选:post、get;
  261. * @param null $appAuthToken 三方应用授权token
  262. * @return 构建好的、签名后的最终跳转URL(GET)或String形式的form(POST)
  263. * @throws Exception
  264. */
  265. public function pageExecute($request, $httpmethod = "POST", $appAuthToken = null)
  266. {
  267. $this->setupCharsets($request);
  268. if (strcasecmp($this->fileCharset, $this->postCharset)) {
  269. // writeLog("本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!");
  270. throw new \Exception("文件编码:[" . $this->fileCharset . "] 与表单提交编码:[" . $this->postCharset . "]两者不一致!");
  271. }
  272. $iv = null;
  273. if (!$this->checkEmpty($request->getApiVersion())) {
  274. $iv = $request->getApiVersion();
  275. } else {
  276. $iv = $this->apiVersion;
  277. }
  278. //组装系统参数
  279. $sysParams["app_id"] = $this->appId;
  280. $sysParams["version"] = $iv;
  281. $sysParams["format"] = $this->format;
  282. $sysParams["sign_type"] = $this->signType;
  283. $sysParams["method"] = $request->getApiMethodName();
  284. $sysParams["timestamp"] = date("Y-m-d H:i:s");
  285. $sysParams["alipay_sdk"] = $this->alipaySdkVersion;
  286. if (!$this->checkEmpty($request->getTerminalType())) {
  287. $sysParams["terminal_type"] = $request->getTerminalType();
  288. }
  289. if (!$this->checkEmpty($request->getTerminalInfo())) {
  290. $sysParams["terminal_info"] = $request->getTerminalInfo();
  291. }
  292. if (!$this->checkEmpty($request->getProdCode())) {
  293. $sysParams["prod_code"] = $request->getProdCode();
  294. }
  295. if (!$this->checkEmpty($request->getNotifyUrl())) {
  296. $sysParams["notify_url"] = $request->getNotifyUrl();
  297. }
  298. if (!$this->checkEmpty($request->getReturnUrl())) {
  299. $sysParams["return_url"] = $request->getReturnUrl();
  300. }
  301. $sysParams["charset"] = $this->postCharset;
  302. if (!$this->checkEmpty($appAuthToken)) {
  303. $sysParams["app_auth_token"] = $appAuthToken;
  304. }
  305. //获取业务参数
  306. $apiParams = $request->getApiParas();
  307. if (method_exists($request, "getNeedEncrypt") && $request->getNeedEncrypt()) {
  308. $sysParams["encrypt_type"] = $this->encryptType;
  309. if ($this->checkEmpty($apiParams['biz_content'])) {
  310. throw new \Exception(" api request Fail! The reason : encrypt request is not supperted!");
  311. }
  312. if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) {
  313. throw new \Exception(" encryptType and encryptKey must not null! ");
  314. }
  315. if ("AES" != $this->encryptType) {
  316. throw new \Exception("加密类型只支持AES");
  317. }
  318. // 执行加密
  319. $enCryptContent = encrypt($apiParams['biz_content'], $this->encryptKey);
  320. $apiParams['biz_content'] = $enCryptContent;
  321. }
  322. //print_r($apiParams);
  323. $totalParams = array_merge($apiParams, $sysParams);
  324. //待签名字符串
  325. $preSignStr = $this->getSignContent($totalParams);
  326. //签名
  327. $totalParams["sign"] = $this->generateSign($totalParams, $this->signType);
  328. if ("GET" == strtoupper($httpmethod)) {
  329. //value做urlencode
  330. $preString = $this->getSignContentUrlencode($totalParams);
  331. //拼接GET请求串
  332. $requestUrl = $this->gatewayUrl . "?" . $preString;
  333. return $requestUrl;
  334. } else {
  335. //拼接表单字符串
  336. return $this->buildRequestForm($totalParams);
  337. }
  338. }
  339. /**
  340. * 建立请求,以表单HTML形式构造(默认)
  341. * @param $para_temp 请求参数数组
  342. * @return 提交表单HTML文本
  343. */
  344. protected function buildRequestForm($para_temp)
  345. {
  346. $sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='" . $this->gatewayUrl . "?charset=" . trim($this->postCharset) . "' method='POST'>";
  347. while (list ($key, $val) = $this->fun_adm_each($para_temp)) {
  348. if (false === $this->checkEmpty($val)) {
  349. //$val = $this->characet($val, $this->postCharset);
  350. $val = str_replace("'", "&apos;", $val);
  351. //$val = str_replace("\"","&quot;",$val);
  352. $sHtml .= "<input type='hidden' name='" . $key . "' value='" . $val . "'/>";
  353. }
  354. }
  355. //submit按钮控件请不要含有name属性
  356. $sHtml = $sHtml . "<input type='submit' value='ok' style='display:none;''></form>";
  357. $sHtml = $sHtml . "<script>document.forms['alipaysubmit'].submit();</script>";
  358. return $sHtml;
  359. }
  360. protected function fun_adm_each(&$array)
  361. {
  362. $res = array();
  363. $key = key($array);
  364. if ($key !== null) {
  365. next($array);
  366. $res[1] = $res['value'] = $array[$key];
  367. $res[0] = $res['key'] = $key;
  368. } else {
  369. $res = false;
  370. }
  371. return $res;
  372. }
  373. public function execute($request, $authToken = null, $appInfoAuthtoken = null, $targetAppId = null)
  374. {
  375. $this->setupCharsets($request);
  376. //如果两者编码不一致,会出现签名验签或者乱码
  377. if (strcasecmp($this->fileCharset, $this->postCharset)) {
  378. // writeLog("本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!");
  379. throw new \Exception("文件编码:[" . $this->fileCharset . "] 与表单提交编码:[" . $this->postCharset . "]两者不一致!");
  380. }
  381. $iv = null;
  382. if (!$this->checkEmpty($request->getApiVersion())) {
  383. $iv = $request->getApiVersion();
  384. } else {
  385. $iv = $this->apiVersion;
  386. }
  387. //组装系统参数
  388. $sysParams["app_id"] = $this->appId;
  389. $sysParams["version"] = $iv;
  390. $sysParams["format"] = $this->format;
  391. $sysParams["sign_type"] = $this->signType;
  392. $sysParams["method"] = $request->getApiMethodName();
  393. $sysParams["timestamp"] = date("Y-m-d H:i:s");
  394. if (!$this->checkEmpty($authToken)) {
  395. $sysParams["auth_token"] = $authToken;
  396. }
  397. $sysParams["alipay_sdk"] = $this->alipaySdkVersion;
  398. if (!$this->checkEmpty($request->getTerminalType())) {
  399. $sysParams["terminal_type"] = $request->getTerminalType();
  400. }
  401. if (!$this->checkEmpty($request->getTerminalInfo())) {
  402. $sysParams["terminal_info"] = $request->getTerminalInfo();
  403. }
  404. if (!$this->checkEmpty($request->getProdCode())) {
  405. $sysParams["prod_code"] = $request->getProdCode();
  406. }
  407. if (!$this->checkEmpty($request->getNotifyUrl())) {
  408. $sysParams["notify_url"] = $request->getNotifyUrl();
  409. }
  410. $sysParams["charset"] = $this->postCharset;
  411. if (!$this->checkEmpty($appInfoAuthtoken)) {
  412. $sysParams["app_auth_token"] = $appInfoAuthtoken;
  413. }
  414. if (!$this->checkEmpty($targetAppId)) {
  415. $sysParams["target_app_id"] = $targetAppId;
  416. }
  417. if (!$this->checkEmpty($this->targetServiceUrl)) {
  418. $sysParams["ws_service_url"] = $this->targetServiceUrl;
  419. }
  420. //获取业务参数
  421. $apiParams = $request->getApiParas();
  422. if (method_exists($request, "getNeedEncrypt") && $request->getNeedEncrypt()) {
  423. $sysParams["encrypt_type"] = $this->encryptType;
  424. if ($this->checkEmpty($apiParams['biz_content'])) {
  425. throw new \Exception(" api request Fail! The reason : encrypt request is not supperted!");
  426. }
  427. if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) {
  428. throw new \Exception(" encryptType and encryptKey must not null! ");
  429. }
  430. if ("AES" != $this->encryptType) {
  431. throw new \Exception("加密类型只支持AES");
  432. }
  433. // 执行加密
  434. $enCryptContent = encrypt($apiParams['biz_content'], $this->encryptKey);
  435. $apiParams['biz_content'] = $enCryptContent;
  436. }
  437. //签名
  438. $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams), $this->signType);
  439. //系统参数放入GET请求串
  440. $requestUrl = $this->gatewayUrl . "?";
  441. foreach ($sysParams as $sysParamKey => $sysParamValue) {
  442. if ($sysParamValue != null) {
  443. $requestUrl .= "$sysParamKey=" . urlencode($this->characet($sysParamValue, $this->postCharset)) . "&";
  444. }
  445. }
  446. $requestUrl = substr($requestUrl, 0, -1);
  447. //发起HTTP请求
  448. try {
  449. $resp = $this->curl($requestUrl, $apiParams);
  450. } catch (Exception $e) {
  451. $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_" . $e->getCode(), $e->getMessage());
  452. return false;
  453. }
  454. //解析AOP返回结果
  455. $respWellFormed = false;
  456. // 将返回结果转换本地文件编码
  457. $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $resp);
  458. $signData = null;
  459. if ("json" == strtolower($this->format)) {
  460. $respObject = json_decode($r);
  461. if (null !== $respObject) {
  462. $respWellFormed = true;
  463. $signData = $this->parserJSONSignData($request, $resp, $respObject);
  464. }
  465. } else if ("xml" == $this->format) {
  466. $disableLibxmlEntityLoader = libxml_disable_entity_loader(true);
  467. $respObject = @ simplexml_load_string($resp);
  468. if (false !== $respObject) {
  469. $respWellFormed = true;
  470. $signData = $this->parserXMLSignData($request, $resp);
  471. }
  472. libxml_disable_entity_loader($disableLibxmlEntityLoader);
  473. }
  474. //返回的HTTP文本不是标准JSON或者XML,记下错误日志
  475. if (false === $respWellFormed) {
  476. var_dump(333);
  477. $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);
  478. return false;
  479. }
  480. // 验签
  481. $this->checkResponseSign($request, $signData, $resp, $respObject);
  482. // 解密
  483. if (method_exists($request, "getNeedEncrypt") && $request->getNeedEncrypt()) {
  484. if ("json" == strtolower($this->format)) {
  485. $resp = $this->encryptJSONSignSource($request, $resp);
  486. // 将返回结果转换本地文件编码
  487. $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $resp);
  488. $respObject = json_decode($r);
  489. } else {
  490. $resp = $this->encryptXMLSignSource($request, $resp);
  491. $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $resp);
  492. $disableLibxmlEntityLoader = libxml_disable_entity_loader(true);
  493. $respObject = @ simplexml_load_string($r);
  494. libxml_disable_entity_loader($disableLibxmlEntityLoader);
  495. }
  496. }
  497. return $respObject;
  498. }
  499. /**
  500. * 转换字符集编码
  501. * @param $data
  502. * @param $targetCharset
  503. * @return string
  504. */
  505. function characet($data, $targetCharset)
  506. {
  507. if (!empty($data)) {
  508. $fileType = $this->fileCharset;
  509. if (strcasecmp($fileType, $targetCharset) != 0) {
  510. $data = mb_convert_encoding($data, $targetCharset, $fileType);
  511. // $data = iconv($fileType, $targetCharset.'//IGNORE', $data);
  512. }
  513. }
  514. return $data;
  515. }
  516. public function exec($paramsArray)
  517. {
  518. if (!isset ($paramsArray["method"])) {
  519. trigger_error("No api name passed");
  520. }
  521. $inflector = new LtInflector;
  522. $inflector->conf["separator"] = ".";
  523. $requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
  524. if (!class_exists($requestClassName)) {
  525. trigger_error("No such api: " . $paramsArray["method"]);
  526. }
  527. $session = isset ($paramsArray["session"]) ? $paramsArray["session"] : null;
  528. $req = new $requestClassName;
  529. foreach ($paramsArray as $paraKey => $paraValue) {
  530. $inflector->conf["separator"] = "_";
  531. $setterMethodName = $inflector->camelize($paraKey);
  532. $inflector->conf["separator"] = ".";
  533. $setterMethodName = "set" . $inflector->camelize($setterMethodName);
  534. if (method_exists($req, $setterMethodName)) {
  535. $req->$setterMethodName ($paraValue);
  536. }
  537. }
  538. return $this->execute($req, $session);
  539. }
  540. /**
  541. * 校验$value是否非空
  542. * if not set ,return true;
  543. * if is null , return true;
  544. **/
  545. protected function checkEmpty($value)
  546. {
  547. if (!isset($value))
  548. return true;
  549. if ($value === null)
  550. return true;
  551. if (trim($value) === "")
  552. return true;
  553. return false;
  554. }
  555. /** rsaCheckV1 & rsaCheckV2
  556. * 验证签名
  557. * 在使用本方法前,必须初始化AopClient且传入公钥参数。
  558. * 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
  559. **/
  560. public function rsaCheckV1($params, $rsaPublicKeyFilePath, $signType = 'RSA')
  561. {
  562. $sign = $params['sign'];
  563. unset($params['sign']);
  564. unset($params['sign_type']);
  565. return $this->verify($this->getSignContent($params), $sign, $rsaPublicKeyFilePath, $signType);
  566. }
  567. public function rsaCheckV2($params, $rsaPublicKeyFilePath, $signType = 'RSA')
  568. {
  569. $sign = $params['sign'];
  570. unset($params['sign']);
  571. return $this->verify($this->getSignContent($params), $sign, $rsaPublicKeyFilePath, $signType);
  572. }
  573. function verify($data, $sign, $rsaPublicKeyFilePath, $signType = 'RSA')
  574. {
  575. if ($this->checkEmpty($this->alipayPublicKey)) {
  576. $pubKey = $this->alipayrsaPublicKey;
  577. $res = "-----BEGIN PUBLIC KEY-----\n" .
  578. wordwrap($pubKey, 64, "\n", true) .
  579. "\n-----END PUBLIC KEY-----";
  580. } else {
  581. //读取公钥文件
  582. $pubKey = file_get_contents($rsaPublicKeyFilePath);
  583. //转换为openssl格式密钥
  584. $res = openssl_get_publickey($pubKey);
  585. }
  586. ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确');
  587. //调用openssl内置方法验签,返回bool值
  588. $result = FALSE;
  589. if ("RSA2" == $signType) {
  590. $result = (openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256) === 1);
  591. } else {
  592. $result = (openssl_verify($data, base64_decode($sign), $res) === 1);
  593. }
  594. if (!$this->checkEmpty($this->alipayPublicKey)) {
  595. //释放资源
  596. openssl_free_key($res);
  597. }
  598. return $result;
  599. }
  600. /**
  601. * 在使用本方法前,必须初始化AopClient且传入公私钥参数。
  602. * 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
  603. **/
  604. public function checkSignAndDecrypt($params, $rsaPublicKeyPem, $rsaPrivateKeyPem, $isCheckSign, $isDecrypt, $signType = 'RSA')
  605. {
  606. $charset = $params['charset'];
  607. $bizContent = $params['biz_content'];
  608. if ($isCheckSign) {
  609. if (!$this->rsaCheckV2($params, $rsaPublicKeyPem, $signType)) {
  610. echo "<br/>checkSign failure<br/>";
  611. exit;
  612. }
  613. }
  614. if ($isDecrypt) {
  615. return $this->rsaDecrypt($bizContent, $rsaPrivateKeyPem, $charset);
  616. }
  617. return $bizContent;
  618. }
  619. /**
  620. * 在使用本方法前,必须初始化AopClient且传入公私钥参数。
  621. * 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
  622. **/
  623. public function encryptAndSign($bizContent, $rsaPublicKeyPem, $rsaPrivateKeyPem, $charset, $isEncrypt, $isSign, $signType = 'RSA')
  624. {
  625. // 加密,并签名
  626. if ($isEncrypt && $isSign) {
  627. $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset);
  628. $sign = $this->sign($encrypted, $signType);
  629. $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>RSA</encryption_type><sign>$sign</sign><sign_type>$signType</sign_type></alipay>";
  630. return $response;
  631. }
  632. // 加密,不签名
  633. if ($isEncrypt && (!$isSign)) {
  634. $encrypted = $this->rsaEncrypt($bizContent, $rsaPublicKeyPem, $charset);
  635. $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$encrypted</response><encryption_type>$signType</encryption_type></alipay>";
  636. return $response;
  637. }
  638. // 不加密,但签名
  639. if ((!$isEncrypt) && $isSign) {
  640. $sign = $this->sign($bizContent, $signType);
  641. $response = "<?xml version=\"1.0\" encoding=\"$charset\"?><alipay><response>$bizContent</response><sign>$sign</sign><sign_type>$signType</sign_type></alipay>";
  642. return $response;
  643. }
  644. // 不加密,不签名
  645. $response = "<?xml version=\"1.0\" encoding=\"$charset\"?>$bizContent";
  646. return $response;
  647. }
  648. /**
  649. * 在使用本方法前,必须初始化AopClient且传入公私钥参数。
  650. * 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
  651. **/
  652. public function rsaEncrypt($data, $rsaPublicKeyFilePath, $charset)
  653. {
  654. if ($this->checkEmpty($this->alipayPublicKey)) {
  655. //读取字符串
  656. $pubKey = $this->alipayrsaPublicKey;
  657. $res = "-----BEGIN PUBLIC KEY-----\n" .
  658. wordwrap($pubKey, 64, "\n", true) .
  659. "\n-----END PUBLIC KEY-----";
  660. } else {
  661. //读取公钥文件
  662. $pubKey = file_get_contents($rsaPublicKeyFilePath);
  663. //转换为openssl格式密钥
  664. $res = openssl_get_publickey($pubKey);
  665. }
  666. ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确');
  667. $blocks = $this->splitCN($data, 0, 30, $charset);
  668. $chrtext = null;
  669. $encodes = array();
  670. foreach ($blocks as $n => $block) {
  671. if (!openssl_public_encrypt($block, $chrtext , $res)) {
  672. echo "<br/>" . openssl_error_string() . "<br/>";
  673. }
  674. $encodes[] = $chrtext ;
  675. }
  676. $chrtext = implode(",", $encodes);
  677. return base64_encode($chrtext);
  678. }
  679. /**
  680. * 在使用本方法前,必须初始化AopClient且传入公私钥参数。
  681. * 公钥是否是读取字符串还是读取文件,是根据初始化传入的值判断的。
  682. **/
  683. public function rsaDecrypt($data, $rsaPrivateKeyPem, $charset)
  684. {
  685. if ($this->checkEmpty($this->rsaPrivateKeyFilePath)) {
  686. //读字符串
  687. $priKey = $this->rsaPrivateKey;
  688. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  689. wordwrap($priKey, 64, "\n", true) .
  690. "\n-----END RSA PRIVATE KEY-----";
  691. } else {
  692. $priKey = file_get_contents($this->rsaPrivateKeyFilePath);
  693. $res = openssl_get_privatekey($priKey);
  694. }
  695. ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  696. //转换为openssl格式密钥
  697. $decodes = explode(',', $data);
  698. $strnull = "";
  699. $dcyCont = "";
  700. foreach ($decodes as $n => $decode) {
  701. if (!openssl_private_decrypt($decode, $dcyCont, $res)) {
  702. echo "<br/>" . openssl_error_string() . "<br/>";
  703. }
  704. $strnull .= $dcyCont;
  705. }
  706. return $strnull;
  707. }
  708. function splitCN($cont, $n = 0, $subnum, $charset)
  709. {
  710. //$len = strlen($cont) / 3;
  711. $arrr = array();
  712. for ($i = $n; $i < strlen($cont); $i += $subnum) {
  713. $res = $this->subCNchar($cont, $i, $subnum, $charset);
  714. if (!empty ($res)) {
  715. $arrr[] = $res;
  716. }
  717. }
  718. return $arrr;
  719. }
  720. function subCNchar($str, $start = 0, $length, $charset = "gbk")
  721. {
  722. if (strlen($str) <= $length) {
  723. return $str;
  724. }
  725. $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
  726. $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
  727. $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
  728. $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
  729. preg_match_all($re[$charset], $str, $match);
  730. $slice = join("", array_slice($match[0], $start, $length));
  731. return $slice;
  732. }
  733. function parserResponseSubCode($request, $responseContent, $respObject, $format)
  734. {
  735. if ("json" == strtolower($format)) {
  736. $apiName = $request->getApiMethodName();
  737. $rootNodeName = str_replace(".", "_", $apiName) . $this->RESPONSE_SUFFIX;
  738. $errorNodeName = $this->ERROR_RESPONSE;
  739. $rootIndex = strpos($responseContent, $rootNodeName);
  740. $errorIndex = strpos($responseContent, $errorNodeName);
  741. if ($rootIndex > 0) {
  742. // 内部节点对象
  743. $rInnerObject = $respObject->$rootNodeName;
  744. } elseif ($errorIndex > 0) {
  745. $rInnerObject = $respObject->$errorNodeName;
  746. } else {
  747. return null;
  748. }
  749. // 存在属性则返回对应值
  750. if (isset($rInnerObject->sub_code)) {
  751. return $rInnerObject->sub_code;
  752. } else {
  753. return null;
  754. }
  755. } elseif ("xml" == $format) {
  756. // xml格式sub_code在同一层级
  757. return $respObject->sub_code;
  758. }
  759. }
  760. function parserJSONSignData($request, $responseContent, $responseJSON)
  761. {
  762. $signData = new SignData();
  763. $signData->sign = $this->parserJSONSign($responseJSON);
  764. $signData->signSourceData = $this->parserJSONSignSource($request, $responseContent);
  765. return $signData;
  766. }
  767. function parserJSONSignSource($request, $responseContent)
  768. {
  769. $apiName = $request->getApiMethodName();
  770. $rootNodeName = str_replace(".", "_", $apiName) . $this->RESPONSE_SUFFIX;
  771. $rootIndex = strpos($responseContent, $rootNodeName);
  772. $errorIndex = strpos($responseContent, $this->ERROR_RESPONSE);
  773. if ($rootIndex > 0) {
  774. return $this->parserJSONSource($responseContent, $rootNodeName, $rootIndex);
  775. } else if ($errorIndex > 0) {
  776. return $this->parserJSONSource($responseContent, $this->ERROR_RESPONSE, $errorIndex);
  777. } else {
  778. return null;
  779. }
  780. }
  781. function parserJSONSource($responseContent, $nodeName, $nodeIndex)
  782. {
  783. $signDataStartIndex = $nodeIndex + strlen($nodeName) + 2;
  784. $signIndex = strrpos($responseContent, "\"" . $this->SIGN_NODE_NAME . "\"");
  785. // 签名前-逗号
  786. $signDataEndIndex = $signIndex - 1;
  787. $indexLen = $signDataEndIndex - $signDataStartIndex;
  788. if ($indexLen < 0) {
  789. return null;
  790. }
  791. return substr($responseContent, $signDataStartIndex, $indexLen);
  792. }
  793. function parserJSONSign($responseJSon)
  794. {
  795. return $responseJSon->sign;
  796. }
  797. function parserXMLSignData($request, $responseContent)
  798. {
  799. $signData = new SignData();
  800. $signData->sign = $this->parserXMLSign($responseContent);
  801. $signData->signSourceData = $this->parserXMLSignSource($request, $responseContent);
  802. return $signData;
  803. }
  804. function parserXMLSignSource($request, $responseContent)
  805. {
  806. $apiName = $request->getApiMethodName();
  807. $rootNodeName = str_replace(".", "_", $apiName) . $this->RESPONSE_SUFFIX;
  808. $rootIndex = strpos($responseContent, $rootNodeName);
  809. $errorIndex = strpos($responseContent, $this->ERROR_RESPONSE);
  810. // $this->echoDebug("<br/>rootNodeName:" . $rootNodeName);
  811. // $this->echoDebug("<br/> responseContent:<xmp>" . $responseContent . "</xmp>");
  812. if ($rootIndex > 0) {
  813. return $this->parserXMLSource($responseContent, $rootNodeName, $rootIndex);
  814. } else if ($errorIndex > 0) {
  815. return $this->parserXMLSource($responseContent, $this->ERROR_RESPONSE, $errorIndex);
  816. } else {
  817. return null;
  818. }
  819. }
  820. function parserXMLSource($responseContent, $nodeName, $nodeIndex)
  821. {
  822. $signDataStartIndex = $nodeIndex + strlen($nodeName) + 1;
  823. $signIndex = strrpos($responseContent, "<" . $this->SIGN_NODE_NAME . ">");
  824. // 签名前-逗号
  825. $signDataEndIndex = $signIndex - 1;
  826. $indexLen = $signDataEndIndex - $signDataStartIndex + 1;
  827. if ($indexLen < 0) {
  828. return null;
  829. }
  830. return substr($responseContent, $signDataStartIndex, $indexLen);
  831. }
  832. function parserXMLSign($responseContent)
  833. {
  834. $signNodeName = "<" . $this->SIGN_NODE_NAME . ">";
  835. $signEndNodeName = "</" . $this->SIGN_NODE_NAME . ">";
  836. $indexOfSignNode = strpos($responseContent, $signNodeName);
  837. $indexOfSignEndNode = strpos($responseContent, $signEndNodeName);
  838. if ($indexOfSignNode < 0 || $indexOfSignEndNode < 0) {
  839. return null;
  840. }
  841. $nodeIndex = ($indexOfSignNode + strlen($signNodeName));
  842. $indexLen = $indexOfSignEndNode - $nodeIndex;
  843. if ($indexLen < 0) {
  844. return null;
  845. }
  846. // 签名
  847. return substr($responseContent, $nodeIndex, $indexLen);
  848. }
  849. /**
  850. * 验签
  851. * @param $request
  852. * @param $signData
  853. * @param $resp
  854. * @param $respObject
  855. * @throws Exception
  856. */
  857. public function checkResponseSign($request, $signData, $resp, $respObject)
  858. {
  859. if (!$this->checkEmpty($this->alipayPublicKey) || !$this->checkEmpty($this->alipayrsaPublicKey)) {
  860. if ($signData == null || $this->checkEmpty($signData->sign) || $this->checkEmpty($signData->signSourceData)) {
  861. throw new \Exception(" check sign Fail! The reason : signData is Empty");
  862. }
  863. // 获取结果sub_code
  864. $responseSubCode = $this->parserResponseSubCode($request, $resp, $respObject, $this->format);
  865. if (!$this->checkEmpty($responseSubCode) || ($this->checkEmpty($responseSubCode) && !$this->checkEmpty($signData->sign))) {
  866. $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);
  867. if (!$checkResult) {
  868. if (strpos($signData->signSourceData, "\\/") > 0) {
  869. $signData->signSourceData = str_replace("\\/", "/", $signData->signSourceData);
  870. $checkResult = $this->verify($signData->signSourceData, $signData->sign, $this->alipayPublicKey, $this->signType);
  871. if (!$checkResult) {
  872. throw new \Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
  873. }
  874. } else {
  875. throw new \Exception("check sign Fail! [sign=" . $signData->sign . ", signSourceData=" . $signData->signSourceData . "]");
  876. }
  877. }
  878. }
  879. }
  880. }
  881. private function setupCharsets($request)
  882. {
  883. if ($this->checkEmpty($this->postCharset)) {
  884. $this->postCharset = 'UTF-8';
  885. }
  886. $str = preg_match('/[\x80-\xff]/', $this->appId) ? $this->appId : print_r($request, true);
  887. $this->fileCharset = mb_detect_encoding($str, "UTF-8, GBK") == 'UTF-8' ? 'UTF-8' : 'GBK';
  888. }
  889. // 获取加密内容
  890. private function encryptJSONSignSource($request, $responseContent)
  891. {
  892. $parsetItem = $this->parserEncryptJSONSignSource($request, $responseContent);
  893. $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex);
  894. $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex);
  895. $bizContent = decrypt($parsetItem->encryptContent, $this->encryptKey);
  896. return $bodyIndexContent . $bizContent . $bodyEndContent;
  897. }
  898. private function parserEncryptJSONSignSource($request, $responseContent)
  899. {
  900. $apiName = $request->getApiMethodName();
  901. $rootNodeName = str_replace(".", "_", $apiName) . $this->RESPONSE_SUFFIX;
  902. $rootIndex = strpos($responseContent, $rootNodeName);
  903. $errorIndex = strpos($responseContent, $this->ERROR_RESPONSE);
  904. if ($rootIndex > 0) {
  905. return $this->parserEncryptJSONItem($responseContent, $rootNodeName, $rootIndex);
  906. } else if ($errorIndex > 0) {
  907. return $this->parserEncryptJSONItem($responseContent, $this->ERROR_RESPONSE, $errorIndex);
  908. } else {
  909. return null;
  910. }
  911. }
  912. private function parserEncryptJSONItem($responseContent, $nodeName, $nodeIndex)
  913. {
  914. $signDataStartIndex = $nodeIndex + strlen($nodeName) + 2;
  915. $signIndex = strpos($responseContent, "\"" . $this->SIGN_NODE_NAME . "\"");
  916. // 签名前-逗号
  917. $signDataEndIndex = $signIndex - 1;
  918. if ($signDataEndIndex < 0) {
  919. $signDataEndIndex = strlen($responseContent) - 1;
  920. }
  921. $indexLen = $signDataEndIndex - $signDataStartIndex;
  922. $encContent = substr($responseContent, $signDataStartIndex + 1, $indexLen - 2);
  923. $encryptParseItem = new EncryptParseItem();
  924. $encryptParseItem->encryptContent = $encContent;
  925. $encryptParseItem->startIndex = $signDataStartIndex;
  926. $encryptParseItem->endIndex = $signDataEndIndex;
  927. return $encryptParseItem;
  928. }
  929. // 获取加密内容
  930. private function encryptXMLSignSource($request, $responseContent)
  931. {
  932. $parsetItem = $this->parserEncryptXMLSignSource($request, $responseContent);
  933. $bodyIndexContent = substr($responseContent, 0, $parsetItem->startIndex);
  934. $bodyEndContent = substr($responseContent, $parsetItem->endIndex, strlen($responseContent) + 1 - $parsetItem->endIndex);
  935. $bizContent = decrypt($parsetItem->encryptContent, $this->encryptKey);
  936. return $bodyIndexContent . $bizContent . $bodyEndContent;
  937. }
  938. private function parserEncryptXMLSignSource($request, $responseContent)
  939. {
  940. $apiName = $request->getApiMethodName();
  941. $rootNodeName = str_replace(".", "_", $apiName) . $this->RESPONSE_SUFFIX;
  942. $rootIndex = strpos($responseContent, $rootNodeName);
  943. $errorIndex = strpos($responseContent, $this->ERROR_RESPONSE);
  944. // $this->echoDebug("<br/>rootNodeName:" . $rootNodeName);
  945. // $this->echoDebug("<br/> responseContent:<xmp>" . $responseContent . "</xmp>");
  946. if ($rootIndex > 0) {
  947. return $this->parserEncryptXMLItem($responseContent, $rootNodeName, $rootIndex);
  948. } else if ($errorIndex > 0) {
  949. return $this->parserEncryptXMLItem($responseContent, $this->ERROR_RESPONSE, $errorIndex);
  950. } else {
  951. return null;
  952. }
  953. }
  954. private function parserEncryptXMLItem($responseContent, $nodeName, $nodeIndex)
  955. {
  956. $signDataStartIndex = $nodeIndex + strlen($nodeName) + 1;
  957. $xmlStartNode = "<" . $this->ENCRYPT_XML_NODE_NAME . ">";
  958. $xmlEndNode = "</" . $this->ENCRYPT_XML_NODE_NAME . ">";
  959. $indexOfXmlNode = strpos($responseContent, $xmlEndNode);
  960. if ($indexOfXmlNode < 0) {
  961. $item = new EncryptParseItem();
  962. $item->encryptContent = null;
  963. $item->startIndex = 0;
  964. $item->endIndex = 0;
  965. return $item;
  966. }
  967. $startIndex = $signDataStartIndex + strlen($xmlStartNode);
  968. $bizContentLen = $indexOfXmlNode - $startIndex;
  969. $bizContent = substr($responseContent, $startIndex, $bizContentLen);
  970. $encryptParseItem = new EncryptParseItem();
  971. $encryptParseItem->encryptContent = $bizContent;
  972. $encryptParseItem->startIndex = $signDataStartIndex;
  973. $encryptParseItem->endIndex = $indexOfXmlNode + strlen($xmlEndNode);
  974. return $encryptParseItem;
  975. }
  976. function echoDebug($content)
  977. {
  978. if ($this->debugInfo) {
  979. echo "<br/>" . $content;
  980. }
  981. }
  982. }