| 一,先注册商业账号paypal官网www.paypal.com二,接下来我们开始沙箱测试;当账户注册成功以后,paypal会分配给开发者账号两个沙箱测试账号(一个买家账号和一个商家账号)。
 去paypal开发者账号管理端查看,登录地址:https://developer.paypal.com,用上面刚刚注册的账号密码即可,然后进入后台看到如下界面
  我画红框的那两个账号就是paypal自动分配给我的,但是这个又是一个坑!!!!!我们可以看到Country的值为C2(代表中国区账号),但是我们千万不要同时拿着这两个账号来进行沙箱收付款测试,因为Paypal规定中国地区和中国地区的账户之间无法实现付款。把其中一个同账号修改为其它国家即可.
 三,给你的商家测试账号是可以单独登录的.登录后,可以查看收款情况.里面的余额是虚拟的.登录地址为https://www.sandbox.paypal.com/,这里需要用上面红框中的商家账号登录四.php代码
 <?php
namespace Home\Controller;
use Think\Controller;
class PaypalController extends Controller {
	 
	
private $account = 'sb-ylrml6894057@business.example.com';
	 
	
private $gateway = 'https://www.sandbox.paypal.com/cgi-bin/webscr?'; 
	public function order(){
		
		
		$order_id=I('get.order_id');
		$price = I('get.price');
		
		$pp_info = array();
		
		$pp_info['cmd']			= '_xclick';
		
		$pp_info['business']	= $this->account;
		
		
		$pp_info['item_name']	= "支付订单:".$order_id;
		$pp_info['amount']		= $price; 
		
		
		
		$pp_info['currency_code']	= 'USD';
		
		
		
		$pp_info['return']		= 'http://www.asml.com/index.php?s=/home/index/user_order.html';	
		$pp_info['invoice']	= $order_id; 
		$pp_info['charset']	= 'utf-8'; 
		$pp_info['no_shipping']	= '2';
		$pp_info['shipping address']	= 'beijing'; 
		$pp_info['no_note']		= '1'; 
		
		$pp_info['cancel_return']	= 'http://www.asml.com/index.php?s=/home/index/user_order.html';	
		
		
		
		$pp_info['notify_url']	= 'http://www.asml.com/index.php?s=/home/paypal/notify/orderid/'.$order_id; 
		$pp_info['rm']	= '2'; 
		$pp_info['lc']	= 'en_US'; 
		$paypal_payment_url = $this->gateway.http_build_query($pp_info); 
		
		header("Location: {$paypal_payment_url}");
	}
	public function notify() {
		
		
		
		$order_id = floor( $_GET['orderid']); 
		
		$order_info = M('order')->where(array('code'=>$order_id))->find();
$id=$order_info['id'];		
		
		
		
		$req = 'cmd=_notify-validate';
		foreach ($_POST as $k=>$v){ 
			$v = urlencode(stripslashes($v)); 
			$req .= "&{$k}={$v}"; 
		} 
	
	
	
		
		$url_par=parse_url($this->gateway);
$fp = fsockopen($url_par[host],"80",$errnum,$errstr,30);
if(!$fp) {
return false;
} else {
fputs($fp, "POST ".$url_par[path]." HTTP/1.1\r\n");
fputs($fp, "Host: ".$url_par[host]."\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($req)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $req . "\r\n\r\n");
while(!feof($fp)) {
$this->validate_ipn_response .= fgets($fp, 1024);
}
fclose($fp); 
}
if (eregi("VERIFIED",$this->validate_ipn_response)) {
	
	
	
				
				
	 
				if(($_POST['payment_status'] != 'Completed' && $_POST['payment_status'] != 'Pending') 
				 OR ($_POST['receiver_email'] != $this->account)
				  OR ($_POST['mc_gross'] != $order_info['allprice'])
				   OR ('USD' != $_POST['mc_currency'])) { 
				
				
				
			
					echo 'fail';exit;
				} else {
					$data['state']=2;
					$orders=M('order_list')->where(array('oid'=>$id))->select();
	            	foreach($orders as $k=>$v){
	                	$product_id=$v['cid'];
	                	$oldkucun=M('contlist')->where(array('id'=>$product_id))->getField('kucun');
	                	$kucun=$oldkucun-$v['num'];
	                	
	                	M('contlist')->where(array('id'=>$product_id))->save($data);
	            	}
					
			
				
				
				
	            	M('order')->where(array('code'=>$_POST['invoice']))->save($data);
					echo 'success';exit;
				} 
} else {
echo 'fail';exit;
}
	} 
}
?>
 |