支付系列 | 支付宝沙箱模式模拟支付

时间:2024-02-19 21:30:25

1、沙箱环境使用说明

2、配置沙箱环境

复制一下文件中的内容

3、扫码后提示一下信息

导致这种错误的原因是我们使用了正式环境的支付宝APP扫描的沙箱环境下的付款二维码,解决办法就是使用沙箱版本的支付宝APP扫描或者使用沙箱版本的支付宝账号密码登录付款即可。

下载地址:https://ur.alipay.com/kIL

 4、下载沙箱版钱包app,支付宝会提供测试账号,里面有余额。

使用以下账号登录沙箱钱包App

 

 

遇到问题:使用了https 电脑网页支付的异步通知死活收不到信息

通过 https://cryptoreport.websecurity.symantec.com/checker/ 检测 提示 

解决办法:

配置一个http协议的域名,不要验证,则可以接受到异步通知的信息。重新配置支付回调配置文件信息

\'notify_url\' => \'http://http.tinywan.com/api/notify\',
\'return_url\' => \'http://http.tinywan.com/api/return\',

异步通知

{
"gmt_create": "2019-11-16+09%3A42%3A12",
"charset": "utf-8",
"gmt_payment": "2019-11-16+09%3A42%3A19",
"notify_time": "2019-11-16+09%3A42%3A20",
"subject": "Tinywan%E6%B5%8B%E8%AF%95%E5%95%86%E5%93%81",
"sign": "c2ndONot0oUd4ZP2aBfSav8Bd716RG3yICVohEn0peL44ORxFrD2EfMiabaaV5PXRJbrLi%2F0ypTK3alw6boOTcnG4eOEW7KIYZA7C6jcrbki2BOnj%2FxQGd2A2R8wo%2FFc0RQOIupWnIvuy5TOEx1aWDaPMae8JatUJIkpfDl6tQN3gkw4poLIngk7q%2FDR4oUGLvMB9qQ%2FSWXhvpzu8%2BclUdgIjbpUn%2B7C5K3gIjwxgeC2utzd%2F7o%2BWif86Hi7K9rMqLlch17sxud2kgeT1GuxDBIcDu8ZYy0MKtqDVtiBUtPnRpX46duKOtxVH4VqyJpX%2F8%2FPfoMs%2Fte1YkMpWu6PSw%3D%3D",
"buyer_id": "2088102169214338",
"invoice_amount": "200.00",
"version": "1.0",
"notify_id": "2019111600222094219014331000593195",
"fund_bill_list": "%5B%7B%22amount%22%3A%22200.00%22%2C%22fundChannel%22%3A%22ALIPAYACCOUNT%22%7D%5D",
"notify_type": "trade_status_sync",
"out_trade_no": "1573868513",
"total_amount": "200.00",
"trade_status": "TRADE_SUCCESS",
"trade_no": "2019111622001414331000043846",
"auth_app_id": "2016090900470841",
"receipt_amount": "200.00",
"point_amount": "0.00",
"app_id": "2016090900470841",
"buyer_pay_amount": "200.00",
"sign_type": "RSA2",
"seller_id": "2088102174818255"
}

同步参数

{
"charset": "utf-8",
"out_trade_no": "1573868513",
"method": "alipay.trade.page.pay.return",
"total_amount": "200.00",
"sign": "wXROS0xz107qQ68DFSpITPFlQitmXLZTUBHoBMV4Vn3NCjJRo0TcEb3ra4oGrT6Qm5C5WXpj1UL2aTB7FccGOJ3ismd2uKCr42PGESkWOUaNhnKDFly5940T3Anq7r2c37PaFZ7aiQai268UFDXiPwpw0U7hoZnTP1qEq89T7TJZplU8yFCoW1GjEpJMz7ggz1bV3GkoHomTbSvw/J8il7sk9kckvIFtjAZgVL+8Z+nPa/Zn8MhHCd5vLS9ZTl+6g5eUfyxP7RaljsVjCEK71mbmUC6CQpdyz4cGPexk/UZkQXXJCpW/Z4e8Gkd1z/B+dPLZmZs0Kzwp8n306sTXvA==",
"trade_no": "2019111622001414331000043846",
"auth_app_id": "2016090900470841",
"version": "v1",
"app_id": "2016090900470841",
"sign_type": "RSA2",
"seller_id": "2088102174818255",
"timestamp": "2019-11-16 09:42:27"
}

 签名验证失败问题

// 签名验证
$aliPay = Pay::alipay($config);
$verifyData = $aliPay->verify(); // InvalidSignException

 错误日志

INVALID_SIGN: Alipay Sign Verify FAILED

 错误原因就是发起支付和异步回调加载的配置文件不统一造成的  

发起支付加载

public function pay()
{
	$config = Config::get(\'pay.alipay\');
	// 沙箱模式
	if ($isTrue = true) {
		$config[\'mode\'] = \'dev\';
	}
	$order = [
		\'out_trade_no\' => time(),
		\'total_amount\' => rand(10,99),
		\'subject\' => \'测试商品\'.rand(111,9999),
	];

	$alipay = Pay::alipay($config)->web($order);
	return $alipay->send();
}

 异步回调加载

$config = Config::get(\'pay.alipay\');
// 沙箱模式
if ($isTrue = true) {
	$config[\'mode\'] = \'dev\';
}

// 签名验证
$aliPay = Pay::alipay($config);
$verifyData = $aliPay->verify(); // InvalidSignException
Log::debug(\'[异步通知] 签名验证参数 \' . json_encode($verifyData));
Log::debug(\'[异步通知] 签名原始数据\'.json_encode($verifyData->all()));
$verifyRes = 0;

配置文件注意

protected $config = [
        ....
       // 这里加载的是支付宝的公钥,而不是应用公钥
	\'ali_public_key\' =>\'AB....\',
	// 加密方式: **RSA2**  
	\'private_key\' => \'MIIEpAIBAAKCAQE==\',
        ....
];        

 

 

  

参考:Android支付宝沙箱环境使用教程