TP妗嗘灦闆嗘垚鏀粯瀹濓紝涓浆椤靛彉鎴恎bk缂栫爜

TP妗嗘灦闆嗘垚鏀粯瀹濓紝涓浆椤靛彉鎴恎bk缂栫爜

銆�tp妗嗘灦涓泦鎴愭敮浠樺疂鐨勫姛鑳斤紝灏嗘敮浠樺疂鐨刣emo渚嬪瓙瀛樺湪鍒颁笅鍥句綅缃甛Extend\Vendor\Alipay
TP妗嗘灦闆嗘垚鏀粯瀹濓紝涓浆椤靛彉鎴恎bk缂栫爜_第1张图片
銆�銆�鐢熸垚鏀粯璁㈠崟
/**
*鏀粯璁㈠崟
*/
publicfunctionpay(){
header("Content-Type:text/html;charset=utf-8");
$id=I('post.oid','','htmlspecialchars');
$DAO=M('order');
$order=$DAO->where("id=".$id)->find();
$error="";
if(!isset($order)){
$error="璁㈠崟涓嶅瓨鍦�";
}elseif($order['PaymentStatus']==1){
$error="姝よ鍗曞凡缁忓畬鎴愶紝鏃犻渶鍐嶆鏀粯锛�";
}elseif($order['PaymentStatus']==2){
$error="姝よ鍗曞凡缁忓彇娑堬紝鏃犳硶鏀粯锛岃閲嶆柊涓嬪崟锛�";
}
if($error!=""){
$this->_FAIL("绯荤粺閿欒",$error,$this->getErrorLinks());
return;
}
$payType=I('post.payType','','htmlspecialchars');
#鏀粯瀹�
if($payType=='alipay'){
$this->payWithAlipay($order);
}
}
銆�鏀粯璁㈠崟鎻愪氦
/**
*浠ユ敮浠樺疂褰㈠紡鏀粯
*@paramunknown_type$order
*/
privatefunctionpayWithAlipay($order){
//寮曞叆鏀粯瀹濈浉鍏崇殑鏂囦欢
require_once(VENDOR_PATH."Alipay/alipay.config.php");
require_once(VENDOR_PATH."Alipay/lib/alipay_submit.class.php");
//鏀粯绫诲瀷
$payment_type="1";
//蹇呭~锛屼笉鑳戒慨鏀�
//鏈嶅姟鍣ㄥ紓姝ラ�氱煡椤甸潰璺緞
$notify_url=C("HOST")."index.php/Alipay/notifyOnAlipay";
//椤甸潰璺宠浆鍚屾閫氱煡椤甸潰璺緞
$return_url=C("HOST")."index.php/Pay/ok";
//鍗栧鏀粯瀹濆笎鎴�
$seller_email=$alipay_config['seller_email'];
//蹇呭~
//鍟嗘埛璁㈠崟鍙�,浠庤鍗曞璞′腑鑾峰彇
$out_trade_no=$order['OrderNum'];
//鍟嗘埛缃戠珯璁㈠崟绯荤粺涓敮涓�璁㈠崟鍙凤紝蹇呭~
//璁㈠崟鍚嶇О
$subject="鐗╂祦鏈嶅姟";
//蹇呭~
//浠樻閲戦
#姝e父閲戦
$price=$order['Price'];
#娴嬭瘯閲戦
#$price=0.1;
//蹇呭~
$body=$subject;
//鍟嗗搧灞曠ず鍦板潃
$show_url=C('HOST');
//鏋勯�犺璇锋眰鐨勫弬鏁版暟缁勶紝鏃犻渶鏀瑰姩
$parameter=array(
"service"=>"create_direct_pay_by_user",
"partner"=>trim($alipay_config['partner']),
"payment_type"=>$payment_type,
"notify_url"=>$notify_url,
"return_url"=>$return_url,
"seller_email"=>$seller_email,
"out_trade_no"=>$out_trade_no,
"subject"=>$subject,
"total_fee"=>$price,
"body"=>$body,
"show_url"=>$show_url,
"_input_charset"=>trim(strtolower($alipay_config['input_charset']))
);
Log::write('鏀粯瀹濊鍗曞弬鏁帮細'.var_export($parameter,true),Log::DEBUG);
//寤虹珛璇锋眰
$alipaySubmit=newAlipaySubmit($alipay_config);
$html_text=$alipaySubmit->buildRequestForm($parameter,"get","鍘绘敮浠�");
echo$html_text;
}
鏀粯瀹濆洖璋冩帴鍙�
<?php
/**
*鏀粯瀹濆洖璋冩帴鍙�
*/
classAlipayActionextendsAction{
/**
*鏀粯瀹濆紓姝ラ�氱煡
*/
publicfunctionnotifyOnAlipay(){
Log::write("notify:".print_r($_REQUEST,true),Log::DEBUG);
require_once(VENDOR_PATH."Alipay/alipay.config.php");
require_once(VENDOR_PATH."Alipay/lib/alipay_notify.class.php");
$orderLogDao=M('orderlog');
//璁$畻寰楀嚭閫氱煡楠岃瘉缁撴灉
$alipayNotify=newAlipayNotify($alipay_config);
$verify_result=$alipayNotify->verifyNotify();
Log::write('verify_result锛�'.var_export($verify_result,true),Log::DEBUG);
if($verify_result){//楠岃瘉鎴愬姛
//鍟嗘埛璁㈠崟鍙�
$out_trade_no=$_POST['out_trade_no'];
//鏀粯瀹濅氦鏄撳彿
$trade_no=$_POST['trade_no'];
//鏍规嵁璁㈠崟鍙疯幏鍙栬鍗�
$DAO=M('order');
$order=$DAO->where("OrderNum='".$out_trade_no."'")->find();
//濡傛灉璁㈠崟涓嶅瓨鍦紝璁剧疆涓�0
if(!isset($order)){
$orderId=0;
}
else{
$orderId=$order['id'];
}
//浜ゆ槗鐘舵��
$trade_status=$_POST['trade_status'];
$log="notifyfromAlipay,trade_status=".$trade_status."alipaysign=".$_POST['sign'].'price='.$_POST['total_fee'];
$orderLog['o_id']=$orderId;
if($_POST['trade_status']=='TRADE_FINISHED'||$_POST['trade_status']=='TRADE_SUCCESS'){
#淇敼璁㈠崟鐘舵��
if((float)$order['Price']!=(float)$_POST['total_fee']){
$data['PaymentStatus']='2';
}else{
$data['PaymentStatus']='1';
}
$DAO->where('id='.$orderId)->save($data);
}
$orderLog['pay_id']=$trade_no;
$orderLog['pay_log']=$log;
$orderLog['pay_type']='alipay';
$orderLog['pay_result']='success';
$orderLogDao->add($orderLog);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
echo"success";//杩斿洖鎴愬姛鏍囪缁欐敮浠樺疂
}
else{
//楠岃瘉涓嶉�氳繃鏃讹紝涔熻褰曚笅鏉�
$orderLog['pay_log']="notifyfromAlipay,浣嗘槸楠岃瘉涓嶉�氳繃锛宻ign=".$_POST['sign'];
$orderLog['o_id']=-1;
$orderLog['pay_type']='alipay';
$orderLog['pay_result']='fail';
$orderLogDao->add($orderLog);
//楠岃瘉澶辫触
echo"fail";
}
}
}
?>
銆�銆�浠婂ぉ鍦╰p妗嗘灦涓泦鎴愭敮浠樺疂鍔熻兘锛岃烦杞敮浠樺疂鐨勬椂鍊欏嚭鐜颁贡鐮侀敊璇��
銆�銆�闇�瑕佽瀹歨eader("Content-Type:text/html;charset=utf-8");
銆�銆�濡傛灉杩樻湁涔辩爜鏌ョ湅鏃ュ織淇℃伅鏄惁鍑虹幇
銆�銆�NOTIC:[2]Cannotmodifyheaderinformation-headersalreadysentby(outputstartedat
銆�銆�涓婇潰閿欒锛屽垹闄ら敊璇枃浠跺紑濮嬬殑绌烘牸
銆�銆�<emid="__mceDel"></em>
English »
AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBengaliBelarusianBulgarianCatalanChinese (Simp)Chinese (Trad)CroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHebrewHindiHungarianIcelandicIndonesianIrishItalianJapaneseKannadaKoreanLaoLatinLatvianLithuanianMacedonianMalayMalteseNorwegianPersianPolishPortugueseRomanianRussianSerbianSlovakSlovenianSpanishSwahiliSwedishTamilTeluguThaiTurkishUkrainianUrduVietnameseWelshYiddish  
Options :  History :  Help :  Feedback
Text-to-speech function is limited to 100 characters

你可能感兴趣的:(TP妗嗘灦闆嗘垚鏀粯瀹濓紝涓浆椤靛彉鎴恎bk缂栫爜)