BasePayHandler.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. *
  11. * @param array $params
  12. * @param string $action
  13. * @return string
  14. */
  15. public static function createHtml($params, $action)
  16. {
  17. $encodeType = isset ($params ['encoding']) ? $params ['encoding'] : 'UTF-8';
  18. $html = <<<eot
  19. <html>
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset={$encodeType}" />
  22. </head>
  23. <body onload="javascript:document.pay_form.submit();">
  24. <form id="pay_form" name="pay_form" action="{$action}" method="post">
  25. eot;
  26. foreach ($params as $key => $value) {
  27. $html .= " <input type=\"hidden\" name=\"{$key}\" id=\"{$key}\" value=\"{$value}\" />\n";
  28. }
  29. $html .= <<<eot
  30. <!-- <input type="submit" type="hidden">-->
  31. </form>
  32. </body>
  33. </html>
  34. eot;
  35. return $html;
  36. }
  37. /**
  38. * @param int $payType
  39. * @return aotu\PayHandler|balpal\PayHandler|huayin\PayHandler|huidao\PayHandler|null
  40. */
  41. public static function getPayHandlerByPayType($payType)
  42. {
  43. switch ($payType) {
  44. case 2:
  45. $handler = new \common\pay\huidao\PayHandler();
  46. break;
  47. case 4:
  48. $handler = new \common\pay\huayin\PayHandler();
  49. break;
  50. case 5:
  51. $handler = new \common\pay\aotu\PayHandler();
  52. break;
  53. case 6:
  54. $handler = new \common\pay\balpal\PayHandler();
  55. break;
  56. default:
  57. $handler = null;
  58. break;
  59. }
  60. return $handler;
  61. }
  62. }