最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

Magento 外挂通用支付模块

Magento 资料整理 ajiang-tuzi 6348浏览

黑五刚过,又遇到几个国外朋叫我帮着维护跟新一些Magento和其他商铺站点.看到盆友们的站 不得不说技术发展的真快啊 虽然拿了几百美元的小费 但是这几天真的是忙成狗, 博客都没法更新咯 要不是 Miyue兄弟发博客我都忘还有博客了于是赶过来 跟新下

这只是一些通用的方法 你可以吧这个方法 放到任何一个站去 当然 取决于你的接口
从这个模块 可以获得
1.订单所有的信息
2.订单所有的支付信息
2.支付模块的信息

首先应该读下这个支付模块 Magento 支付模块常用函数

<?php   
/*
*WWW.WEICOT.COM
*pay post module
*version 0.2.0 2015-5-10
*NO . 003 his
*BlueWeicot Pay
***********************
*WeicotPayment new version
*version 2.0
*2015-12-04
*1050653098@qq.com
*历史接口是 指多个模块共用的接口
*或 必须适配的旧的接口 
*/

  
//必要信息获得模块 接口适配 1
        $incrementID=$_REQUEST['orderNo'];  
        $cardNo=$_REQUEST['cardNo'];
	    $cvv  =$_REQUEST['cvv'];
	    $cardExpireYear   =$_REQUEST['expirationYear'];
	    $cardExpireMonth  =$_REQUEST['expirationMonth'];
		
		
		
		
//自带函数加载模块
require_once("../app/Mage.php");//先引用
$app = Mage::app('default');
//$incrementID='C00014307'; 
$orders = Mage::getModel('sales/order')->getCollection();
$orders->addAttributeToFilter('increment_id',$incrementID); //其中 $incrementID为订单号
$orders->addAttributeToSelect('*');
$orders->load();
$alldata = $orders->getData();
$sales_order = Mage::getModel('sales/order')->load($alldata[0]['entity_id']);
$billingAddress=$sales_order->getBillingAddress();
$Email=$sales_order->getData('customer_email'); //客户的邮件

//与通用接口做适配  比如 zencart opencart 等可以通用的组件 接口适配2
$orderNo=$_REQUEST['orderNo']; 
$orderInfo=$sales_order;
$Amount=sprintf('%.2f', $orderInfo->getGrandTotal());



//直接调用支付模块

   class WeicotPayBox{
	   
   function  getInfo($orderInfo,$cardNo,$cvv,$cardExpireYear,$cardExpireMonth) {
	$standard = Mage::getModel('pocketccns/payment');
	//注意大小写
    $paymentUrl = $standard->getCreditFristPayUrl();
    $paymentData = $standard->setOrder($orderInfo)->getWeicotPayInfo($cardNo,$cvv,$cardExpireYear,$cardExpireMonth);
	//组合定订单信息
    $response = $this->getSystemReturnInfo($paymentUrl, $paymentData);//获得返回信息
    $result = json_decode($response);//对信息进行解码
	$returnData=$this->dataproAction($result);//进行 数组转换
	return  $returnData;
	//$this->orderProcessAction($returnData);//对订单进行判断处理
    //echo $paymentUrl;
   //var_dump($paymentData);
   //var_dump($result);
   }

   //发送订单信息模块
  function getSystemReturnInfo($paymentUrl,$paymentData) {
		//Mage::log($paymentData, null, 'newpay.log');
		if(function_exists('curl_init') && function_exists('curl_exec')) {
			$info = $this->vpost($paymentUrl,$paymentData);
		} else {
			$info = $this->hpost($paymentUrl,$paymentData);
		}
		//Mage::log($info, null, 'newpay.log');
		return $info;
	}
	
	/*
	 * 通用模块 Curl 
	 * Store additional order information
	 * @param String $url
	 * @param String $data
     * @return Array $returnInfo
     */
	function vpost($url, $data) {
        $curl_cookie="";
	    foreach ($_COOKIE as $key => $value) {
	       $curl_cookie.=$key."=".$value.";"; 
	    }
		$curl = curl_init(); 
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		curl_setopt($curl, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_PORT, 443);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		curl_setopt($curl, CURLOPT_TIMEOUT, 300);
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIE,$curl_cookie);
		$tmpInfo = curl_exec($curl);
		curl_close($curl);
		return $tmpInfo;
    }
	//非cul传值
	function hpost($url, $data){
		$website = $_SERVER['HTTP_HOST'];
		$cookie="";
		foreach ($_COOKIE as $key => $value) {	           
		   $cookie.=$key."=".$value.";"; 	                          	
		}
        $options  = array(
			'http' => array(
			'method' => "POST",
			'header' => "Accept-language: en\r\n" . "Cookie: $cookie\r\n" . "referer:$website \r\n",
			'content-type' => "multipart/form-data",
			'content' => $data,
			'timeout' => 15 * 60 
            )
        );
        //创建并返回一个流的资源
        $context  = stream_context_create($options);
        $result   = file_get_contents($url, false, $context);
        return $result;
    }
	public function dataproAction($result)
	{
		//返回数据处理
		$returnData = array(
			'transType' 	=> $result->transType,
			'orderNo'		=> $result->orderNo,
			'merNo'			=> $result->merNo,
			'terNo'			=> $result->terNo,
			'currencyCode'	=> $result->currencyCode,
			'amount'		=> $result->amount,
			'tradeNo' 		=> $result->tradeNo,
			'respCode'		=> $result->respCode,
			'respMsg'		=> $result->respMsg
		);
		return $returnData;
	}
   }
//函数开开始  
$PayModule=new WeicotPayBox;
$returnData=$PayModule->getInfo($orderInfo,$cardNo,$cvv,$cardExpireYear,$cardExpireMonth);

// 支付 模块 结束

//重新支付模块
function RePay($OrderID,$Amount,$Email,$Payment){
	//非必须
	$Amount=de($Amount*100);
	//双重验证加密
    $Url="/index.php/Weicot/index/view/?order[number]=$OrderID&order[email]=$Email";
	$Id=base64_encode('&pay='.$Payment.'&pr='.$Amount);
	$Uid='**********';
        //参数在次混淆 这个 个我就不发勒 一切为了安全
	$Track='<a target="_blank" href=\''.$Url.$Uid.'\'>CLICK HERE</a>';
	return $Track;
	}
$RePayUrl=RePay($incrementID,$Amount,$Email,'0');
//价格 不是必须参数 用来做混淆的

//状态处理模块 还是历史接口 适配 3 
   if($returnData['respCode'] == '00') {
				//成功 代码	
				$payin="成功";
	            $Bankinfo="Payment success";
				$Succeend='1';
			}else {
				
				$Bankinfo=$returnData['respMsg'];
				$BankNo='1';
				//失败代码
				//$info='Payment Failed!:'.$returnData['respMsg'];
				//适配 历史接口
				//$Bankinfo=$info.'--Please try after 15 minutes or more by '.$RePayUrl.', or <a href="/contacts" target="_blank">Contact us</a> thanks<br />';
	            $payin="失败";
				$Succeend='0';
		}
	
	
	

//历史接口  适配 4
//历史接口  
//订单状态更改模块
//成功邮件发送模块
//在次发送带付款链接邮件模块
require_once "state.php";

/////////////////////////////////////////////////////
$BillNO=$_REQUEST['orderNo']; 
$TradeNO=$BillNO;//订单追踪号
$ReSucceend=$returnData['respCode'];
$pay='WeicotPayBox';

//日志 历史接口适配5
//写入日志 文件
//短日志
file_put_contents("paylogtest.txt",$BillNO."|".$pay."|".date("Y-m-d H:i:s")."|".$payin."\r\n",FILE_APPEND);
//长日志
file_put_contents("Dipaylogtest.txt",date("Y-m-d H:i:s")."|".$BillNO."|".$Amount."|".$pay."|".$TradeNO."|".$ReSucceend."|".$returnData['respMsg']."|".$ApsLog."->".$GetApsLog."\r\n",FILE_APPEND);	
//返回页面
include('newpay.php'); 
//orderProcessAction($returnData);
//构造重行支付链接 模块

效果图
效果
这是老版本的函数

$shipstatedata=empty($shipstate)? "Am":$shipstate;
$billstatedata=empty($billstate)? "Am":$billstate;
$Adrress=$shipstate.$shipcity.$shipcountry.$shipcompany.$shipstreet;
$md5src = $merNo.$orderNo.$Freight.$amount.$Fee.$_REQUEST['currency'].$returnURL.$_REQUEST['email'].$merKey;	
$MD5info = strtoupper(md5($md5src));
$lineitems= array(
				'sku' => $sku,
				'name' => $name,
				'description' => $description,
				'cost' => $cost,
				'taxable' => $taxable,
				'qty' => $qty
			);
			$c=1;
		if(!is_array($lineitems)) $lineitems=array();
		foreach($lineitems as $lineitem)
		{
			 $GoodListInfo=$GoodListInfo."<Goods><GoodsName>".$lineitem['name']."</GoodsName><Qty>"."1"."</Qty>"."<Price>".sprintf('%.2f',$lineitem['cost'])."</Price></Goods>";
			$c++;	
		}
	  $baseStr='<?xml version="1.0" encoding="UTF-8" ?><Order>';
      $baseStr =$baseStr."<MerNo>".$merNo."</MerNo>";
	  $baseStr =$baseStr."<ShopName>".$_REQUEST['']."</ShopName>";   
      $baseStr =$baseStr."<BillNo>".$orderNo."</BillNo><GoodsList>";
	  $baseStr =$baseStr.$GoodListInfo;
	  $baseStr =$baseStr."</GoodsList><Amount>".$amount."</Amount>";
	  $baseStr =$baseStr."<Fee>".$Fee."</Fee>";
      $baseStr =$baseStr."<Freight>".$Freight."</Freight>";
      $baseStr =$baseStr."<CurrencyCode>".$_REQUEST['currency']."</CurrencyCode>";
      $baseStr =$baseStr."<BFirstName>".$_REQUEST['billFirstName']."</BFirstName>"; 
      $baseStr =$baseStr."<BLastName>".$_REQUEST['billLastName']."</BLastName>";
      $baseStr =$baseStr."<Phone>".$_REQUEST['phone']."</Phone>";
      $baseStr =$baseStr."<Email>".$_REQUEST['email']."</Email>";
      $baseStr =$baseStr."<BillAddress>".$_REQUEST['billAddress']."</BillAddress>";
      $baseStr =$baseStr."<BillCity>".$_REQUEST['billCity']."</BillCity>"; 
      $baseStr =$baseStr."<BillState>".$billstate."</BillState>";
      $baseStr =$baseStr."<BillCountry>".$_REQUEST['billCountry']."</BillCountry>"; 
      $baseStr =$baseStr."<BillZip>".$_REQUEST['billZip']."</BillZip>";
      $baseStr =$baseStr."<SFirstName>".$_REQUEST['shipFirstName']."</SFirstName>";  
      $baseStr =$baseStr."<SLastName>".$_REQUEST['shipLastName']."</SLastName>"; 
	  $baseStr =$baseStr."<ShipAddress>".$Adrress."</ShipAddress>"; 
	  $baseStr =$baseStr."<ShipCity>".$_REQUEST['shipCity']."</ShipCity>"; 
	  $baseStr =$baseStr."<ShipState>".$shipstatedata."</ShipState>"; 
      $baseStr =$baseStr."<ShipCountry>".$_REQUEST['shipCountry']."</ShipCountry>";
      $baseStr =$baseStr."<ShipZip>".$_REQUEST['shipZip']."</ShipZip>"; 
      $baseStr =$baseStr."<Language>".'2' ."</Language>"; 
      $baseStr =$baseStr."<LangCode>".'en'."</LangCode>"; 
      $baseStr =$baseStr."<Currency>".'15'."</Currency>"; 
	  $baseStr =$baseStr."<ReturnURL>".$returnURL."</ReturnURL>"; 
	  $baseStr =$baseStr."<Remark>".'SDF'."</Remark>"; 
      $baseStr =$baseStr."<MD5info>".$MD5info."</MD5info>"; 
	  $baseStr =$baseStr."<IssuingBank>"."HSUB"."</IssuingBank>";
      $baseStr =$baseStr."<CardNo>".$_REQUEST['cardNo']."</CardNo>";
	  $baseStr =$baseStr."<CVV>".$_REQUEST['cvv']."</CVV>";
	  $baseStr =$baseStr."<ExpireYear>".$_REQUEST['expirationYear']."</ExpireYear>";
	  $baseStr =$baseStr."<ExpireMonth>".$_REQUEST['expirationMonth']."</ExpireMonth>";
	  $baseStr =$baseStr."<AcceptLanguage>".$acceptLanguage."</AcceptLanguage>";
	  $baseStr =$baseStr."<UserAgent>".$userAgent."</UserAgent>";
	  $baseStr =$baseStr."<Ipaddress>".$_REQUEST['payIp']."</Ipaddress></Order>";
$TradeInfo=base64_encode(urlencode($baseStr));
$url="https://ssl.weicot.com/payment/DirPaymentProcess";
$Postresult=CurlPost($url,'TradeInfo='.$TradeInfo);
$Decrydata=base64_decode($Postresult);
$splitdata=array();
$edata=explode('&',$Decrydata);
foreach($edata as $key=>$value){
	$splitdata[$key]= explode('=',$value);
}
$TradeNO= $splitdata[0][1];
$BillNO=  $splitdata[1][1]; 
$Currency=$splitdata[8][1];
$Amount=  $splitdata[9][1];
$Succeend=$splitdata[2][1];
$MD5info= $splitdata[4][1];
$Bankinfo= $splitdata[3][1];

$RePayUrl=PayBlue($orderNo,$amount,$_REQUEST['email'],'0');
function error($ostr){
$ostr=preg_replace("#[^0-9]#",'',$ostr);
$error=array(
1=>"failed to pay",
2=>"in processing",
2007=>"failed to pay",
3000=>"failed to pay"
);
(!empty($error[$ostr]))?$eput=$error[$ostr]:$eput=$error[2];
return $eput;
}

if ($Succeend==1){
	$payin="成功";
	$Bankinfo="Payment success";
}else{
	$Bankinfo='Failed to pay--Please try after 15 minutes or more by '.$RePayUrl.', or <a href="/contacts" target="_blank">Contact us</a> thanks<br />';
	$payin="失败";
}
require_once "state.php";
require_once "getstate.php"; 
$pay='xxxxxxxxx';
file_put_contents("nexpay.txt",$BillNO."|".$pay."|".date("Y-m-d H:i:s")."|".$payin."\r\n",FILE_APPEND);
file_put_contents("nexpaylong.txt",date("Y-m-d H:i:s")."|".$BillNO."|".$Amount."|".$pay."|".$TradeNO."|".$Succeend."|".$splitdata[3][1]."|".$ApsLog."->".$GetApsLog."\r\n",FILE_APPEND);


function CurlPost($url, $data) { 
		
		    $curl_cookie="";
	        foreach ($_COOKIE as $key => $value) {
	           
	           $curl_cookie.=$key."=".$value.";"; 
	                          	
	        }
	           
		$curl = curl_init(); 
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
		//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($curl, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_PORT, 443);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
		curl_setopt($curl, CURLOPT_TIMEOUT, 300);
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIE,$curl_cookie);
		$tmpInfo = curl_exec($curl);
		
		curl_close($curl);
		return $tmpInfo;
	} 
	include('result.php'); 

转载请注明:(●--●) Hello.My Weicot » Magento 外挂通用支付模块

蜀ICP备15020253号-1