人人商城支付回调init()中type参数的涵义

人人商城支付系统有很多功能或插件都在调用,在支付回调时,该如何区分是哪里发起的支付行为,并做相应的支付后处理呢?

今天大概分享一下老杨的理解吧,以微信支付为例。

回调函数位置

addons\ewei_shopv2\payment\wechat\notify.php

在支付中,通过以下方法发起

$wechat = m('common')->wechat_build($params, $options, 999);

上述函数中第三个参数是发起支付行为的起点,告诉回调函数在支付后该调用哪个方法来处理后续行为,最终传入 init() 函数中。

找到 init() 函数,它根据不同的 type 值调用不同的处理方法,列举几个常见的type对应的涵义,直接注释在代码里吧,供各位参考:

public function init(){
	if( $this->type == "0" ){//订单支付 order
		$this->order();
	}
	else{
		if( $this->type == "1" ){//账户余额充值 recharge
			$this->recharge();
		}
		else{
			if( $this->type == "2" ){//积分商城
				$this->creditShop();
			}
			else{
				if( $this->type == "3" ){//积分商城
					$this->creditShopFreight();
				}
				else{
					if( $this->type == "4" ){//优惠券
						$this->coupon();
					}
					else{
						if( $this->type == "5" ){//拼团
							$this->groups();
						}
						else{
							if( $this->type == "6" ){
								$this->threen();
							}
							else{
								if( $this->type == "10" ){
									$this->mr();
								}
								else{
									if( $this->type == "11" ){
										$this->pstoreCredit();
									}
									else{
										if( $this->type == "12" ){
											$this->pstore();
										}
										else{
											if( $this->type == "13" ){//人人收银台 优惠券
												$this->cashier();
											}
											else{
												if( $this->type == "14" ){
													$this->wxapp_order();
												}
												else{
													if( $this->type == "15" ){
														$this->wxapp_recharge();
													}
													else{
														if( $this->type == "16" ){
															$this->wxapp_coupon();
														}
														else{
															if( $this->type == "17" ){
																$this->grant();
															}
															else{
																if( $this->type == "18" ){
																	$this->plugingrant();
																}
																else{
																	if( $this->type == "19" ){
																		$this->wxapp_groups();
																	}
																	else{
																		if( $this->type == "20" ){
																			$this->wxapp_membercard();
																		}
																		else{
																			if( $this->type == "21" ){
																				$this->membercard();
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	$this->success();
}

或者另一版本

public function init(){
	//订单支付 order
	if( $this->type == "0" ){
		$this->order();
	}
	//账户余额充值 recharge
	elseif( $this->type == "1" ){
		$this->recharge();
	}
	//积分商城
	elseif( $this->type == "2" ){
		$this->creditShop();
	}
	//积分商城
	elseif( $this->type == "3" ){
		$this->creditShopFreight();
	}
	//优惠券
	elseif( $this->type == "4" ){
		$this->coupon();
	}
	//拼团
	elseif( $this->type == "5" ){
		$this->groups();
	}
	elseif( $this->type == "6" ){
		$this->threen();
	}
	elseif( $this->type == "10" ){
		$this->mr();
	}
	elseif( $this->type == "11" ){
		$this->pstoreCredit();
	}
	elseif( $this->type == "12" ){
		$this->pstore();
	}
	//人人收银台 优惠券
	elseif( $this->type == "13" ){
		$this->cashier();
	}
	elseif( $this->type == "14" ){
		$this->wxapp_order();
	}
	elseif( $this->type == "15" ){
		$this->wxapp_recharge();
	}
	elseif( $this->type == "16" ){
		$this->wxapp_coupon();
	}
	elseif( $this->type == "17" ){
		$this->grant();
	}
	elseif( $this->type == "18" ){
		$this->plugingrant();
	}
	elseif( $this->type == "19" ){
		$this->wxapp_groups();
	}
	elseif( $this->type == "20" ){
		$this->wxapp_membercard();
	}
	elseif( $this->type == "21" ){
		$this->membercard();
	}
	
	$this->success();
}