BasePayHandler.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace common\pay;
  3. use yii\base\Component;
  4. class BasePayHandler extends Component
  5. {
  6. public $notifyUrl;
  7. public $returnUrl;
  8. /**
  9. * 构造自动提交表单
  10. * @param array $params
  11. * @param string $action
  12. * @return string
  13. */
  14. public static function createHtml($params, $action)
  15. {
  16. $encodeType = isset ($params ['encoding']) ? $params ['encoding'] : 'UTF-8';
  17. $html = <<<eot
  18. <html>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset={$encodeType}" />
  21. </head>
  22. <body onload="javascript:document.pay_form.submit();">
  23. <form id="pay_form" name="pay_form" action="{$action}" method="post">
  24. eot;
  25. foreach ($params as $key => $value) {
  26. $html .= " <input type=\"hidden\" name=\"{$key}\" id=\"{$key}\" value=\"{$value}\" />\n";
  27. }
  28. $html .= <<<eot
  29. <!-- <input type="submit" type="hidden">-->
  30. </form>
  31. </body>
  32. </html>
  33. eot;
  34. return $html;
  35. }
  36. /**
  37. * POST提交表单信息
  38. * @param array $postData
  39. * @param string $url
  40. * @return string
  41. */
  42. public static function curlPost($postData, $url)
  43. {
  44. $ch = curl_init($url);
  45. curl_setopt($ch, CURLOPT_POST, 1);
  46. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  47. curl_setopt($ch, CURLOPT_HEADER, 0);
  48. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  49. curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
  50. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
  51. $response = curl_exec($ch);
  52. return $response;
  53. }
  54. /**
  55. * @param int $payType
  56. * @return aomei\PayHandler|aotu\PayHandler|balpal\PayHandler|huayin\PayHandler|huidao\PayHandler|xiaoyun\PayHandler|yef\PayHandler
  57. */
  58. public static function getPayHandlerByPayType($payType)
  59. {
  60. file_put_contents('huiqi5.txt',$payType);
  61. switch ($payType) {
  62. case 1:
  63. $handler = new \common\pay\renren\PayHandler();
  64. break;
  65. case 2:
  66. $handler = new \common\pay\wangtong\PayHandler();
  67. break;
  68. case 3:
  69. $handler = new \common\pay\sand\PayHandler();
  70. break;
  71. case 4:
  72. $handler = new \common\pay\shangxinshuntong\PayHandler();
  73. break;
  74. case 5:
  75. $handler = new \common\pay\threexmta\PayHandler();
  76. break;
  77. case 6:
  78. $handler = new \common\pay\xunjie\PayHandler();
  79. break;
  80. case 7:
  81. $handler = new \common\pay\ctype\PayHandler();
  82. break;
  83. case 8:
  84. $handler = new \common\pay\kexing\PayHandler();
  85. break;
  86. case 10:
  87. $handler = new \common\pay\otczhifu\PayHandler();
  88. break;
  89. case 11:
  90. $handler = new \common\pay\yinliantiaozhuan\PayHandler();
  91. break;
  92. case 12:
  93. $handler = new \common\pay\yinliantiaozhuan2\PayHandler();
  94. break;
  95. case 13:
  96. $handler = new \common\pay\yinliantiaozhuan3\PayHandler();
  97. break;
  98. case 14:
  99. $handler = new \common\pay\jiedeng\PayHandler();
  100. break;
  101. case 15:
  102. $handler = new \common\pay\eagle\PayHandler();
  103. break;
  104. case 16:
  105. $handler = new \common\pay\duisi\PayHandler();
  106. break;
  107. case 17:
  108. $handler = new \common\pay\duigong\PayHandler();
  109. break;
  110. case 18:
  111. $handler = new \common\pay\globalpay\PayHandler();
  112. break;
  113. case 19:
  114. $handler = new \common\pay\payplat\PayHandler();
  115. break;
  116. default:
  117. $handler = null;
  118. break;
  119. }
  120. return $handler;
  121. }
  122. }