AopClient.php 42 KB

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