Authored by 郝肖肖

通过支付方式获取支付类方法封装

@@ -338,6 +338,7 @@ class PayModel @@ -338,6 +338,7 @@ class PayModel
338 $result = array( 338 $result = array(
339 'id' => $payId, 339 'id' => $payId,
340 'pay_code' => $paymentParams['data']['payCode'], 340 'pay_code' => $paymentParams['data']['payCode'],
  341 + 'payName' => $paymentParams['data']['payName'],
341 'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : '' 342 'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : ''
342 ); 343 );
343 } 344 }
@@ -403,6 +403,7 @@ class PaymentModel @@ -403,6 +403,7 @@ class PaymentModel
403 $result = array( 403 $result = array(
404 'id' => $payId, 404 'id' => $payId,
405 'pay_code' => $paymentParams['data']['payCode'], 405 'pay_code' => $paymentParams['data']['payCode'],
  406 + 'payName' => $paymentParams['data']['payName'],
406 'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : '' 407 'pay_params' => isset($paymentParams['data']['payParams']) ? $paymentParams['data']['payParams'] : ''
407 ); 408 );
408 } 409 }
@@ -23,10 +23,7 @@ class NoticeController extends WebAction @@ -23,10 +23,7 @@ class NoticeController extends WebAction
23 */ 23 */
24 public function alipaynoticeAction() 24 public function alipaynoticeAction()
25 { 25 {
26 - $payment = PayModel::getPaymentById(2);  
27 - $payService = PayFactory::factory($payment);  
28 -  
29 - $res = $payService->parseResponse($_POST); //支付宝通知使用的 26 + $res = $this->getParseResponse($_POST, 2);
30 if ($res->payResult != -1) { 27 if ($res->payResult != -1) {
31 $this->payResultProc($res, 2); 28 $this->payResultProc($res, 2);
32 echo "success"; 29 echo "success";
@@ -39,9 +36,7 @@ class NoticeController extends WebAction @@ -39,9 +36,7 @@ class NoticeController extends WebAction
39 */ 36 */
40 public function alipayreturnAction() 37 public function alipayreturnAction()
41 { 38 {
42 - $payment = PayModel::getPaymentById(2);  
43 - $payService = PayFactory::factory($payment);  
44 - $res = $payService->parseResponse($_GET); 39 + $res = $this->getParseResponse($_GET, 2);
45 $dealResult = $this->payResultProc($res, 2); 40 $dealResult = $this->payResultProc($res, 2);
46 $dealResult['payData'] = array('payWay' => '支付宝'); 41 $dealResult['payData'] = array('payWay' => '支付宝');
47 $this->commonShowResult($dealResult); 42 $this->commonShowResult($dealResult);
@@ -52,9 +47,7 @@ class NoticeController extends WebAction @@ -52,9 +47,7 @@ class NoticeController extends WebAction
52 */ 47 */
53 public function alibarcodenoticeAction() 48 public function alibarcodenoticeAction()
54 { 49 {
55 - $payment = PayModel::getPaymentById(17);  
56 - $payService = PayFactory::factory($payment);  
57 - $res = $payService->parseResponse($_POST); //支付宝通知使用的 50 + $res = $this->getParseResponse($_POST, 17);
58 if ($res->payResult != -1) { 51 if ($res->payResult != -1) {
59 $this->payResultProc($res, 17); 52 $this->payResultProc($res, 17);
60 echo "success"; 53 echo "success";
@@ -67,9 +60,7 @@ class NoticeController extends WebAction @@ -67,9 +60,7 @@ class NoticeController extends WebAction
67 */ 60 */
68 public function alibarcodereturnAction() 61 public function alibarcodereturnAction()
69 { 62 {
70 - $payment = PayModel::getPaymentById(17);  
71 - $payService = PayFactory::factory($payment);  
72 - $res = $payService->parseResponse($_GET); 63 + $res = $this->getParseResponse($_GET, 17);
73 $dealResult = $this->payResultProc($res, 17); 64 $dealResult = $this->payResultProc($res, 17);
74 $dealResult['payData'] = array('payWay' => '支付宝'); 65 $dealResult['payData'] = array('payWay' => '支付宝');
75 $this->commonShowResult($dealResult); 66 $this->commonShowResult($dealResult);
@@ -80,9 +71,7 @@ class NoticeController extends WebAction @@ -80,9 +71,7 @@ class NoticeController extends WebAction
80 */ 71 */
81 public function allinpaynoticeAction() 72 public function allinpaynoticeAction()
82 { 73 {
83 - $payment = PayModel::getPaymentById(16);  
84 - $payService = PayFactory::factory($payment);  
85 - $res = $payService->parseResponse($_POST); 74 + $res = $this->getParseResponse($_POST, 16);
86 if ($res->payResult != -1) { 75 if ($res->payResult != -1) {
87 $this->payResultProc($res, 16); 76 $this->payResultProc($res, 16);
88 echo "success"; 77 echo "success";
@@ -95,9 +84,7 @@ class NoticeController extends WebAction @@ -95,9 +84,7 @@ class NoticeController extends WebAction
95 */ 84 */
96 public function allinpayreturnAction() 85 public function allinpayreturnAction()
97 { 86 {
98 - $payment = PayModel::getPaymentById(16);  
99 - $payService = PayFactory::factory($payment);  
100 - $res = $payService->parseResponse($_POST); 87 + $res = $this->getParseResponse($_POST, 16);
101 $dealResult = $this->payResultProc($res, 16); 88 $dealResult = $this->payResultProc($res, 16);
102 $dealResult['payData'] = array('payWay' => '通联支付'); 89 $dealResult['payData'] = array('payWay' => '通联支付');
103 $this->commonShowResult($dealResult); 90 $this->commonShowResult($dealResult);
@@ -108,9 +95,7 @@ class NoticeController extends WebAction @@ -108,9 +95,7 @@ class NoticeController extends WebAction
108 */ 95 */
109 public function aliexpressgatewayreturnAction() 96 public function aliexpressgatewayreturnAction()
110 { 97 {
111 - $payment = PayModel::getPaymentById(13);  
112 - $payService = PayFactory::factory($payment);  
113 - $res = $payService->parseResponse($_GET); 98 + $res = $this->getParseResponse($_GET, 13);
114 $dealResult = $this->payResultProc($res, 13); 99 $dealResult = $this->payResultProc($res, 13);
115 $dealResult['payData'] = array('payWay' => '支付宝'); 100 $dealResult['payData'] = array('payWay' => '支付宝');
116 $this->commonShowResult($dealResult); 101 $this->commonShowResult($dealResult);
@@ -121,9 +106,7 @@ class NoticeController extends WebAction @@ -121,9 +106,7 @@ class NoticeController extends WebAction
121 */ 106 */
122 public function aliexpressgatewaynoticeAction() 107 public function aliexpressgatewaynoticeAction()
123 { 108 {
124 - $payment = PayModel::getPaymentById(13);  
125 - $payService = PayFactory::factory($payment);  
126 - $res = $payService->parseResponse($_POST); //支付宝通知使用的 109 + $res = $this->getParseResponse($_POST, 13);
127 if ($res->payResult != -1) { 110 if ($res->payResult != -1) {
128 $this->payResultProc($res, 13); 111 $this->payResultProc($res, 13);
129 echo "success"; 112 echo "success";
@@ -136,10 +119,7 @@ class NoticeController extends WebAction @@ -136,10 +119,7 @@ class NoticeController extends WebAction
136 */ 119 */
137 public function alibanknoticeAction() 120 public function alibanknoticeAction()
138 { 121 {
139 - $payment = PayModel::getPaymentById(12);  
140 - $payService = PayFactory::factory($payment);  
141 - $res = $payService->parseResponse($_POST);  
142 - 122 + $res = $this->getParseResponse($_POST, 12);
143 if ($res->payResult != -1) { 123 if ($res->payResult != -1) {
144 $this->payResultProc($res, 12); 124 $this->payResultProc($res, 12);
145 echo "success"; 125 echo "success";
@@ -153,9 +133,7 @@ class NoticeController extends WebAction @@ -153,9 +133,7 @@ class NoticeController extends WebAction
153 */ 133 */
154 public function alibankreturnAction() 134 public function alibankreturnAction()
155 { 135 {
156 - $payment = PayModel::getPaymentById(12);  
157 - $payService = PayFactory::factory($payment);  
158 - $res = $payService->parseResponse($_GET); 136 + $res = $this->getParseResponse($_GET, 12);
159 $dealResult = $this->payResultProc($res, 12); 137 $dealResult = $this->payResultProc($res, 12);
160 $dealResult['payData'] = array('payWay' => '银行卡'); 138 $dealResult['payData'] = array('payWay' => '银行卡');
161 $this->commonShowResult($dealResult); 139 $this->commonShowResult($dealResult);
@@ -166,9 +144,7 @@ class NoticeController extends WebAction @@ -166,9 +144,7 @@ class NoticeController extends WebAction
166 */ 144 */
167 public function chinabankAction() 145 public function chinabankAction()
168 { 146 {
169 - $payment = PayModel::getPaymentById(4);  
170 - $payService = PayFactory::factory($payment);  
171 - $res = $payService->parseResponse($_POST); 147 + $res = $this->getParseResponse($_POST, 4);
172 $dealResult = $this->payResultProc($res, 4); 148 $dealResult = $this->payResultProc($res, 4);
173 $dealResult['payData'] = array('payWay' => '网银在线'); 149 $dealResult['payData'] = array('payWay' => '网银在线');
174 $this->commonShowResult($dealResult); 150 $this->commonShowResult($dealResult);
@@ -179,9 +155,7 @@ class NoticeController extends WebAction @@ -179,9 +155,7 @@ class NoticeController extends WebAction
179 */ 155 */
180 public function chinabankautorevAction() 156 public function chinabankautorevAction()
181 { 157 {
182 - $payment = PayModel::getPaymentById(4);  
183 - $payService = PayFactory::factory($payment);  
184 - $res = $payService->parseResponse($_POST); 158 + $res = $this->getParseResponse($_POST, 4);
185 if ($res->payResult != -1) { 159 if ($res->payResult != -1) {
186 $this->payResultProc($res, 4); 160 $this->payResultProc($res, 4);
187 echo "ok"; 161 echo "ok";
@@ -196,11 +170,8 @@ class NoticeController extends WebAction @@ -196,11 +170,8 @@ class NoticeController extends WebAction
196 */ 170 */
197 public function tenpayAction() 171 public function tenpayAction()
198 { 172 {
199 - $payment = PayModel::getPaymentById(1);  
200 - $payService = PayFactory::factory($payment);  
201 - $rspParams = $payService->parseResponse($_GET); //财付通是以get方式回复的。  
202 -  
203 - $dealResult = $this->payResultProc($rspParams, 1); 173 + $res = $this->getParseResponse($_GET, 1);
  174 + $dealResult = $this->payResultProc($res, 1);
204 $dealResult['payData'] = array('payWay' => '财付通'); 175 $dealResult['payData'] = array('payWay' => '财付通');
205 $this->commonShowResult($dealResult); 176 $this->commonShowResult($dealResult);
206 } 177 }
@@ -211,9 +182,7 @@ class NoticeController extends WebAction @@ -211,9 +182,7 @@ class NoticeController extends WebAction
211 */ 182 */
212 public function shengpayreturnAction() 183 public function shengpayreturnAction()
213 { 184 {
214 - $payment = PayModel::getPaymentById(11);  
215 - $payService = PayFactory::factory($payment);  
216 - $res = $payService->parseResponse($_POST); 185 + $res = $this->getParseResponse($_POST, 11);
217 $dealResult = $this->payResultProc($res, 11); 186 $dealResult = $this->payResultProc($res, 11);
218 $dealResult['payData'] = array('payWay' => '盛付通'); 187 $dealResult['payData'] = array('payWay' => '盛付通');
219 $this->commonShowResult($dealResult); 188 $this->commonShowResult($dealResult);
@@ -224,9 +193,7 @@ class NoticeController extends WebAction @@ -224,9 +193,7 @@ class NoticeController extends WebAction
224 */ 193 */
225 public function shengpaynoticeAction() 194 public function shengpaynoticeAction()
226 { 195 {
227 - $payment = PayModel::getPaymentById(11);  
228 - $payService = PayFactory::factory($payment);  
229 - $res = $payService->parseResponse($_POST); 196 + $res = $this->getParseResponse($_POST, 11);
230 if ($res->payResult != -1) { 197 if ($res->payResult != -1) {
231 $this->payResultProc($res, 11); 198 $this->payResultProc($res, 11);
232 echo "OK"; 199 echo "OK";
@@ -293,9 +260,7 @@ class NoticeController extends WebAction @@ -293,9 +260,7 @@ class NoticeController extends WebAction
293 */ 260 */
294 public function unionpaywebreturnAction() 261 public function unionpaywebreturnAction()
295 { 262 {
296 - $payment = PayModel::getPaymentById(25);  
297 - $payService = PayFactory::factory($payment);  
298 - $res = $payService->parseResponse($_REQUEST); 263 + $res = $this->getParseResponse($_REQUEST, 25);
299 $dealResult = $this->payResultProc($res, 25); 264 $dealResult = $this->payResultProc($res, 25);
300 $dealResult['payData'] = array('payWay' => '银联在线支付'); 265 $dealResult['payData'] = array('payWay' => '银联在线支付');
301 $this->commonShowResult($dealResult); 266 $this->commonShowResult($dealResult);
@@ -306,9 +271,7 @@ class NoticeController extends WebAction @@ -306,9 +271,7 @@ class NoticeController extends WebAction
306 */ 271 */
307 public function unionpaywebnoticeAction() 272 public function unionpaywebnoticeAction()
308 { 273 {
309 - $payment = PayModel::getPaymentById(25);  
310 - $payService = PayFactory::factory($payment);  
311 - $res = $payService->parseResponse($_REQUEST); 274 + $res = $this->getParseResponse($_REQUEST, 25);
312 if ($res->payResult != -1) { 275 if ($res->payResult != -1) {
313 $this->payResultProc($res, 25); 276 $this->payResultProc($res, 25);
314 echo "OK"; 277 echo "OK";
@@ -322,9 +285,7 @@ class NoticeController extends WebAction @@ -322,9 +285,7 @@ class NoticeController extends WebAction
322 */ 285 */
323 public function alimobilenoticeminiAction() 286 public function alimobilenoticeminiAction()
324 { 287 {
325 - $payment = PayModel::getPaymentById(20);  
326 - $payService = PayFactory::factory($payment);  
327 - $res = $payService->parseResponse($_POST); //支付宝通知使用的 288 + $res = $this->getParseResponse($_POST, 20);
328 if ($res->payResult != -1) { 289 if ($res->payResult != -1) {
329 $this->payResultProc($res, 20); 290 $this->payResultProc($res, 20);
330 echo "OK"; 291 echo "OK";
@@ -334,7 +295,28 @@ class NoticeController extends WebAction @@ -334,7 +295,28 @@ class NoticeController extends WebAction
334 295
335 exit(); 296 exit();
336 } 297 }
  298 + /**
  299 + * 获取支付方式类对象
  300 + * @param type array $Parameters 回调参数
  301 + * @param type int $payment 支付方式
  302 + * @return type object
  303 + */
  304 + private function getParseResponse($Parameters, $payment)
  305 + {
  306 + $payment = PayModel::getPaymentById($payment);
  307 + $payService = PayFactory::factory($payment);
  308 + $res = $payService->parseResponse($Parameters);
  309 +
  310 + if (empty($res->bankName)) {
  311 + $res->bankName = empty($payment['payName']) ? '' : $payment['payName'];
  312 + }
337 313
  314 + if (empty($res->bankCode)) {
  315 + $res->bankCode = empty($payment['pay_code']) ? '' : $payment['pay_code'];
  316 + }
  317 +
  318 + return $res;
  319 + }
338 320
339 /** 321 /**
340 * 通用显示结果的方法 322 * 通用显示结果的方法
@@ -16,9 +16,7 @@ class PayreturnController extends WebAction @@ -16,9 +16,7 @@ class PayreturnController extends WebAction
16 */ 16 */
17 public function alipayreturnAction() 17 public function alipayreturnAction()
18 { 18 {
19 - $payment = PaymentModel::getPaymentById(2);  
20 - $payService = PayFactory::factory($payment);  
21 - $res = $payService->parseResponse($_GET); 19 + $res = $this->getParseResponse($_GET, 2);
22 $dealResult = $this->payResultProc($res, 2); 20 $dealResult = $this->payResultProc($res, 2);
23 $dealResult['payData'] = array('payWay' => '支付宝'); 21 $dealResult['payData'] = array('payWay' => '支付宝');
24 $this->commonShowResult($dealResult); 22 $this->commonShowResult($dealResult);
@@ -67,9 +65,7 @@ class PayreturnController extends WebAction @@ -67,9 +65,7 @@ class PayreturnController extends WebAction
67 */ 65 */
68 public function unionpaywebreturnAction() 66 public function unionpaywebreturnAction()
69 { 67 {
70 - $payment = PaymentModel::getPaymentById(25);  
71 - $payService = PayFactory::factory($payment);  
72 - $res = $payService->parseResponse($_REQUEST); 68 + $res = $this->getParseResponse($_REQUEST, 25);
73 $dealResult = $this->payResultProc($res, 25); 69 $dealResult = $this->payResultProc($res, 25);
74 $dealResult['payData'] = array('payWay' => '银联在线支付'); 70 $dealResult['payData'] = array('payWay' => '银联在线支付');
75 $this->commonShowResult($dealResult); 71 $this->commonShowResult($dealResult);
@@ -79,15 +75,34 @@ class PayreturnController extends WebAction @@ -79,15 +75,34 @@ class PayreturnController extends WebAction
79 */ 75 */
80 public function alibankreturnAction() 76 public function alibankreturnAction()
81 { 77 {
82 - $payment = PaymentModel::getPaymentById(12);  
83 -  
84 - $payService = PayFactory::factory($payment);  
85 - $res = $payService->parseResponse($_GET); 78 + $res = $this->getParseResponse($_GET, 12);
86 $dealResult = $this->payResultProc($res, 12); 79 $dealResult = $this->payResultProc($res, 12);
87 $dealResult['payData'] = array('payWay' => '支联支付'); 80 $dealResult['payData'] = array('payWay' => '支联支付');
88 $this->commonShowResult($dealResult); 81 $this->commonShowResult($dealResult);
89 } 82 }
90 /** 83 /**
  84 + * 获取支付方式类对象
  85 + * @param type array $Parameters 回调参数
  86 + * @param type int $payment 支付方式
  87 + * @return type object
  88 + */
  89 + private function getParseResponse($Parameters, $payment)
  90 + {
  91 + $payment = PayModel::getPaymentById($payment);
  92 + $payService = PayFactory::factory($payment);
  93 + $res = $payService->parseResponse($Parameters);
  94 +
  95 + if (empty($res->bankName)) {
  96 + $res->bankName = empty($payment['payName']) ? '' : $payment['payName'];
  97 + }
  98 +
  99 + if (empty($res->bankCode)) {
  100 + $res->bankCode = empty($payment['pay_code']) ? '' : $payment['pay_code'];
  101 + }
  102 +
  103 + return $res;
  104 + }
  105 + /**
91 * 通用显示结果的方法 106 * 通用显示结果的方法
92 * @param array $dealResult 107 * @param array $dealResult
93 */ 108 */