| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace common\pay;
- use yii\base\Component;
- class BasePayHandler extends Component
- {
- public $notifyUrl;
- public $returnUrl;
- /**
- * 构造自动提交表单
- *
- * @param array $params
- * @param string $action
- * @return string
- */
- public static function createHtml($params, $action)
- {
- $encodeType = isset ($params ['encoding']) ? $params ['encoding'] : 'UTF-8';
- $html = <<<eot
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset={$encodeType}" />
- </head>
- <body onload="javascript:document.pay_form.submit();">
- <form id="pay_form" name="pay_form" action="{$action}" method="post">
- eot;
- foreach ($params as $key => $value) {
- $html .= " <input type=\"hidden\" name=\"{$key}\" id=\"{$key}\" value=\"{$value}\" />\n";
- }
- $html .= <<<eot
- <!-- <input type="submit" type="hidden">-->
- </form>
- </body>
- </html>
- eot;
- return $html;
- }
- /**
- * @param int $payType
- * @return aotu\PayHandler|balpal\PayHandler|huayin\PayHandler|huidao\PayHandler|null
- */
- public static function getPayHandlerByPayType($payType)
- {
- switch ($payType) {
- case 2:
- $handler = new \common\pay\huidao\PayHandler();
- break;
- case 4:
- $handler = new \common\pay\huayin\PayHandler();
- break;
- case 5:
- $handler = new \common\pay\aotu\PayHandler();
- break;
- case 6:
- $handler = new \common\pay\balpal\PayHandler();
- break;
- default:
- $handler = null;
- break;
- }
- return $handler;
- }
- }
|