直接上代码:
<?php
namespace app\controller;
use app\BaseController;
// require 'vendor/autoload.php';
use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Kernel\Config;
//http://laremehpe.test.org/index.php/Index/index
class Index extends BaseController
{
public function initPay()
{
$options = new Config();
$options->protocol = 'http'; // 这个地方注意如果是https没有配置证书相关的东西会报错
$options->gatewayHost = 'openapi-sandbox.dl.alipaydev.com'; // 这个地方注意不要添加http头和 /gateway.do 后缀,反正就是不能直接复制阿里的gateway
$options->signType = 'RSA2';
$options->appId = '9021000136604992';
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = 'MIIEPDI3o2YQrJ1o7EhzFfFAJcV0MZ0YyUKFx09ZyV8IE+SvcPF1NxA2R8h6km2eUMcqNPVx5gmXw33zQEY6040iSc9do9gU5Apg7ezgHtSf+G+nxNHcIv+Ycmn60YJIYqeAMiBm5rhcMlyOQutaskf4uoRZvVVqfXN/UVd7gq3pGj152gFPajrzYlP6YmeE6YYA+/1nAdGG68lJSWMUXR+l3T7iIR9amcrCEBsqUwJlC4v0RAOyZTy4QkW1aLHIlaW/wzA4ezEppt5y4IDrQmYIIch8lgAAtDA6gQO3FNbpfz/yvwQceGVUMAzR967ZveZKcbBU/sXhktTk6PZAnpGwIDAQABAoIBACowf2DErT42CwtHrP1N487NsWav5cM3Hat26ZMDCKSKykLJLdk7NuQqVDSpmO5G3g4+l09rR/b4RMILRIxbYQnEKw9zhiNBUZAZHdUqsqi0nAJEY6ediqdSRGyh5zwe8hrzruP5JdhmQYoFHalSMN4PNgy1lsohPZrPFmdFhxpFICeLwKLnLGZ5i6lxG6I3FcjbXsGz1CI3PlsJLpX3jAduJtesnMqdydRHChBH9vkAyR39d1wXMkW6r2tgdqmASb7OxHVtizaAEKlhXjCfhg+8ESvRXBMCY3d2Z5cyfzhI44FqaRb2a1dZiDHPkbmBPY871dp+O7eUNHk/7vY+GyECgYEA+zHtpsxDpaVyrv+hJlnbbb7GDb1MV6JIG4oEkqlGfXSWgeCwZ/bwpwso5qTq37ycnkt72FezoTtJei7LOeV5HFcrfx0i7bsu/3s+I86yk60bo/4eZk6PgDy4RNiRXgzjA9Zphljd9d6xh4bk6FxShF5jaT3M7w8zVdzLn13nc2cCgYEAk3hZ9Yz5vZnJplV/tRoSmN2daJydgORynLk4DPl5Aa+ab2U7XvqrLkypB2Uo4WowZ2yRMJ2/I5KTBPtL5I/E55cOSaDOjJbF2V4+kVHGbVvAfXg3mOeTk0V90iuz2gP56VKIt5ja9Pl6KwqjxrJCISi0RdFRSCY5VZM21jfMYC0CgYEAiGpx/J57sk6qfH0ZACHWd8AeAMIn3oOkE0id+SPywxj4z6m9Q4io4p695Jv1bfIZQCIQLMpcJBh1a+RTu6pyXkC8v3iMSnzYJijA82NCOc7N7v6Hddn+No9DJyhRsbjf5GqhvjMuv2LkGIzabZINwhMce7/zNnST1XJmJrMxicsCgYAVWq4cIoffbq+GiIbvoJDk1eJ/TX55NZtrGl8FcfKVzendC5mnTUEQeUVYrstWqNvNfikgExekfQsRA5qfxDnNF1CYVNLUBNkterowrNjA6TJceNYELDRwdPWdQ3rNrRm5MZxeiaHbK20HYokIsrNkvdIs8fyFKBPRUnn0VywfGQKBgBVoN2anKCo1207l4l9E2XtTypOPN6Wc9FkxbUWgaOJOd+WdJBReS8x0hKIYckd2dMCrIGOa+zXuyQiId5go6LKMFE5/fIGJXCgvZT1LqKvPdzUdSpqC6x63PPBaK4T5mU/S+SWTNdpD0NRX3Ild53lOD3gN0T/tbeNT/aR6szja';
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
$options->alipayPublicKey = 'MIIBIjAAAOCAQ8AMIIBCgKCAQEAi5w35KhW8TUun1oswnXXlf3lJYiU1Feuxkx/ScMj9ZiLWEWNDxQvTtWrGJsgPMWDPMz0g6mbO7T0xrHJwX6QBnFwlUMJwmOjcojuysiWz8TAkOQUYnr2A+n/9Bv2xqMG14Im7nxNhP7En0VVCv9vSOnyPe+eLji55m0tMafOqBYOUuaLcf9e9tjLyElgVjkzQeRxRlLYoysaP2dMDt+ooxhASsq+e0NQYh3+PFdIWjHr89nf1T2SIkEmRszQkNciFUiQIAbDJj6kCUEaRvXFSls3uhK+wnar5BCw0YYRDsAl1gkYsc0KXR58nsr573SQ/FE93//Gq/7cOjwj+wo24wIDAQAB';
//可设置异步通知接收服务地址(可选)
$options->notifyUrl = "";
Factory::setOptions($options);
}
public function pay()
{
$product = "iphone";
$price = '9.99';
$outTradeNo = '2088722033490345';
$this->initPay();
$result = Factory::payment()->page()->pay($product, $outTradeNo, $price, "https://www.taobao.com"); // 这个taobao.com 用于用户支付成功后跳转的页面
return $result->body;
}
}
标签:证书,阿里,沙箱,源码,php,com,options,sdk From: https://www.cnblogs.com/laremehpe/p/18145152