人人商城

common.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */$log = new PhpLog ( SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL );
  6. function coverParamsToString($params) {
  7. $sign_str = '';
  8. ksort ( $params );
  9. foreach ( $params as $key => $val ) {
  10. if ($key == 'signature') {
  11. continue;
  12. }
  13. $sign_str .= sprintf ( "%s=%s&", $key, $val );
  14. }
  15. return substr ( $sign_str, 0, strlen ( $sign_str ) - 1 );
  16. }
  17. function coverStringToArray($str) {
  18. $result = array ();
  19. if (! empty ( $str )) {
  20. $temp = preg_split ( '/&/', $str );
  21. if (! empty ( $temp )) {
  22. foreach ( $temp as $key => $val ) {
  23. $arr = preg_split ( '/=/', $val, 2 );
  24. if (! empty ( $arr )) {
  25. $k = $arr ['0'];
  26. $v = $arr ['1'];
  27. $result [$k] = $v;
  28. }
  29. }
  30. }
  31. }
  32. return $result;
  33. }
  34. function deal_params(&$params) {
  35. if (! empty ( $params ['customerInfo'] )) {
  36. $params ['customerInfo'] = base64_decode ( $params ['customerInfo'] );
  37. }
  38. if (! empty ( $params ['encoding'] ) && strtoupper ( $params ['encoding'] ) == 'utf-8') {
  39. foreach ( $params as $key => $val ) {
  40. $params [$key] = iconv ( 'utf-8', 'UTF-8', $val );
  41. }
  42. }
  43. }
  44. function deflate_file(&$params) {
  45. global $log;
  46. foreach ( $_FILES as $file ) {
  47. $log->LogInfo ( "---------处理文件---------" );
  48. if (file_exists ( $file ['tmp_name'] )) {
  49. $params ['fileName'] = $file ['name'];
  50. $file_content = file_get_contents ( $file ['tmp_name'] );
  51. $file_content_deflate = gzcompress ( $file_content );
  52. $params ['fileContent'] = base64_encode ( $file_content_deflate );
  53. $log->LogInfo ( "压缩后文件内容为>" . base64_encode ( $file_content_deflate ) );
  54. } else {
  55. $log->LogInfo ( ">>>>文件上传失败<<<<<" );
  56. }
  57. }
  58. }
  59. function deal_file($params) {
  60. global $log;
  61. if (isset ( $params ['fileContent'] )) {
  62. $log->LogInfo ( "---------处理后台报文返回的文件---------" );
  63. $fileContent = $params ['fileContent'];
  64. if (empty ( $fileContent )) {
  65. $log->LogInfo ( '文件内容为空' );
  66. } else {
  67. $content = gzuncompress ( base64_decode ( $fileContent ) );
  68. $root = SDK_FILE_DOWN_PATH;
  69. $filePath = null;
  70. if (empty ( $params ['fileName'] )) {
  71. $log->LogInfo ( "文件名为空" );
  72. $filePath = $root . $params ['merId'] . '_' . $params ['batchNo'] . '_' . $params ['txnTime'] . 'txt';
  73. } else {
  74. $filePath = $root . $params ['fileName'];
  75. }
  76. $handle = fopen ( $filePath, "w+" );
  77. if (! is_writable ( $filePath )) {
  78. $log->LogInfo ( "文件:" . $filePath . "不可写,请检查!" );
  79. } else {
  80. file_put_contents ( $filePath, $content );
  81. $log->LogInfo ( "文件位置 >:" . $filePath );
  82. }
  83. fclose ( $handle );
  84. }
  85. }
  86. }
  87. function create_html($params, $action) {
  88. $encodeType = isset ( $params ['encoding'] ) ? $params ['encoding'] : 'UTF-8';
  89. $html = <<<eot
  90. <html>
  91. <head>
  92. <meta http-equiv="Content-Type" content="text/html; charset={$encodeType}" />
  93. </head>
  94. <body onload="javascript:document.pay_form.submit();">
  95. <form id="pay_form" name="pay_form" action="{$action}" method="post">
  96. eot;
  97. foreach ( $params as $key => $value ) {
  98. $html .= " <input type=\"hidden\" name=\"{$key}\" id=\"{$key}\" value=\"{$value}\" />\n";
  99. }
  100. $html .= <<<eot
  101. <input type="submit" type="hidden" value="稍等,支付跳转跳..." style="border:none;">
  102. </form>
  103. </body>
  104. </html>
  105. eot;
  106. return $html;
  107. }
  108. ?>