_inWhiteList){ return true; } $this->_Account = $this->getKey($this->_apiCode); //验证是否具有访问这个接口的权限 if(!isset($this->_Account['ali_seller_id']) || !isset($this->_Account['app_auth_token']) || !isset($this->_Account['sys_service_provider_id']) || !isset($this->_Account['app_id']) || !isset($this->_Account['alipay_url'])){ HelperService::returnJson(['code'=>400,'msg'=>'alipay interface unauthorized access','data'=>[]]); } $this->_AliSellerId = $this->_Account['ali_seller_id']; $this->_AppAuthToken = $this->_Account['app_auth_token']; $this->_SysServiceProviderId = $this->_Account['sys_service_provider_id']; $this->_AppId = $this->_Account['app_id']; Config::set('AliSellerId',$this->_AliSellerId); } public function platformAlipay(){ $params = $this->_params; $rule = [ 'return_url'=>'require', 'out_trade_no'=>'require', 'total_amount'=>'require', 'discountable_amount'=>'require', 'subject'=>'require', 'goods_detail'=>'require', 'store_id'=>'require', 'terminal_id'=>'require', 'extend_params'=>'require', ]; $validate = new Validate($rule); if(!$validate->check($params)){ HelperService::returnJson(['code'=>400,'msg'=>$validate->getError()]); } Log::record("platformAlipay:".$params); $body = ""; try { $apiCode = $this->_apiCode; $submitForm = Wappay::pay(array_filter([ 'out_trade_no' => $params['out_trade_no'], 'subject' => "{$params['subject']}($body)",//售卖项目(Iphone6 16G) 'total_amount' => $params['total_amount'], 'discountable_amount' => $params['discountable_amount'], 'body' => $body, 'auth_token' => $this->_AppAuthToken, 'extend_params'=>['sys_service_provider_id'=>$this->_SysServiceProviderId], 'seller_id' => $this->_AliSellerId, 'operator_id' => isset($params['operator_id']) ? $params['operator_id'] : 'cs_vapi', 'terminal_id' => $params['terminal_id'], 'timeout_express' => '1m' ]), [ 'gatewayUrl' => 'https://openapi.alipay.com/gateway.do', 'app_id' => $this->_AppId, 'merchant_private_key' => file_get_contents("./COMPANY_LIST/$apiCode/alipay/app_private_key.pem"), 'alipay_public_key' => file_get_contents("./COMPANY_LIST/$apiCode/alipay/app_public_key.pem"), 'sign_type' => 'RSA2', 'format' => 'JSON', 'return_url' => $params['return_url'], 'notify_url' => "http://{$_SERVER['SERVER_NAME']}/expand/Alipay/notifyPlatformAlipay", ]); Log::record("$submitForm"); $this->assign('submitForm', $submitForm); }catch (\Exception $ex){ die(""); } return $this->fetch('alipay/pay'); } /** * 支付宝异步通知 */ public function notifyPlatformAlipay(){ $this->getInput(); $params = $this->_sysParams; $rule = [ 'out_trade_no'=>'require', 'total_amount'=>'require', 'trade_no'=>'require' ]; $validate = new Validate($rule); if(!$validate->check($params)){ HelperService::returnJson(['code'=>400,'msg'=>$validate->getError()]); } $outTradeNoArr = explode('_', "{$params['out_trade_no']}"); $orderNo = current($outTradeNoArr); $companyCode = end($outTradeNoArr); if(Cache::has("ali_{$orderNo}")){ die('success'); } try { $data = [ 'order_no' => "{$orderNo}", 'total_fee' => "{$params['total_amount']}", 'out_trade_no' => "{$params['out_trade_no']}", 'add_ts' => time(), 'alipay_msg' => json_encode($params), 'trade_no' => "{$params['trade_no']}", 'company_code' => $companyCode, ]; $this->_Account = $this->getKey($companyCode); $alipayUrl = is_array($this->_Account['alipay_url'])?$this->_Account['alipay_url']:["{$this->_Account['alipay_url']}"]; foreach($alipayUrl as $aliUrl){ Cache::set("ali_{$orderNo}",time(),86400*365); $times = 3; while($times--){ $res = HelperService::httpPost($aliUrl, json_encode($data)); $return = HelperService::$_httpReturn; HelperService::addLog($return,$aliUrl,'alipay'); if($res !== false){ break; } } } die('success'); }catch (\Exception $ex){ HelperService::addLog($ex->getMessage(),"",'alipay'); die('fail(exception)'); } } }