AopClient.php 42 KB

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