1、说明:此次使用的LikeShop版本是 单商户标准商城系统
2、出现的问题:
后台进行退款操作时,退款接口报错
3、检查支付宝配置,appid、公钥、私钥都没错
4、支付宝后台查看,发现加签方式中有说明:“注:使用(资金支出类接口)必须使用证书方式。”
5、确定问题:
退款类接口属于“资金支出类接口”,那就把加签方式改为“公钥证书”
6、其它问题
LikeShop后台只有appid、公钥、私钥等配置,那么检查支付接口:
发现/application/common/server/AlipayServer.php文件中getOptions()方法中只配置了支付宝公钥
7、继而发现,此处调用支付宝接口能力时,是使用的EasySDK
8、那就找找EasySDK的接口文档,发现demo已经写好了,有公钥和公钥证书的支付方式的演示代码
//公钥支付演示demo
public function getTestAccount()
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->appId = '<-- 请填写您的AppId,例如:2019022663440152 -->';
$options->signType = 'RSA2';
$options->alipayPublicKey = '<-- 请填写您的支付宝公钥,例如:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAumX1EaLM4ddn1Pia4SxTRb62aVYxU8I2mHMqrcpQU6F01mIO/DjY7R4xUWcLi0I2oH/BK/WhckBq6ZOEPJnODqH20TAdTLNxPSl4qGxamjBO+RuInBy+Bc2hFHq3pNv6hTAfktggRKkKzDlDEUwgSLE7d2eL7P6rwIDAQAB -->';
$options->merchantPrivateKey = $this->getPrivateKey($options->appId);
return $options;
}
//公钥证书支付演示demo
public function getTestCertAccount()
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->appId = '<-- 请填写您的AppId,例如:2019051064521003 -->';
$options->signType = 'RSA2';
$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/alipayCertPublicKey_RSA2.crt" -->';
$options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/alipayRootCert.crt" -->';
$options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:dirname(__FILE__) . "/resources/fixture/appCertPublicKey_2019051064521003.crt" -->';
$options->merchantPrivateKey = $this->getPrivateKey($options->appId);
return $options;
}
9、依葫芦画瓢,把demo移植过来,把支付宝商家中心生成的证书下载,放到任意目录,再根据demo进行调用:
//支付设置
public function getOptions()
{
$result = (new Pay())->where(['code' => 'alipay'])->find();
if (empty($result)) {
throw new \Exception('请配置好支付设置');
}
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
// $options->gatewayHost = 'openapi.alipaydev.com'; //测试沙箱地址
$options->signType = 'RSA2';
$options->appId = $result['config']['app_id'] ?? '';
// 应用私钥
$options->merchantPrivateKey = $result['config']['private_key'] ?? '';
//支付宝公钥证书
$options->alipayCertPath = Env::get('config_path')."/alipay_crt/alipayCertPublicKey_RSA2.crt";
$options->alipayRootCertPath = Env::get('config_path')."/alipay_crt/alipayRootCert.crt";
$options->merchantCertPath = Env::get('config_path')."/alipay_crt/appCertPublicKey_2021003xxxxxx.crt";
//支付宝公钥
//$options->alipayPublicKey = $result['config']['ali_public_key'] ?? '';
//回调地址
$options->notifyUrl = url('payment/aliNotify', '', '', true);
return $options;
}
10、再次调用退款,已经可以成功退款了,支付测试也没问题,有遇到其它问题的童鞋请评论区留言