TP妗嗘灦闆嗘垚鏀粯瀹濓紝涓浆椤靛彉鎴恎bk缂栫爜
銆�tp妗嗘灦涓泦鎴愭敮浠樺疂鐨勫姛鑳斤紝灏嗘敮浠樺疂鐨刣emo渚嬪瓙瀛樺湪鍒颁笅鍥句綅缃甛Extend\Vendor\Alipay
銆�銆�鐢熸垚鏀粯璁㈠崟
/**
*鏀粯璁㈠崟
*/
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