composer 社区 安装alipaysdk
public function getOptions(){
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->signType = 'RSA2';
$options->appId = 'XXXXXXXXXX';
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$yao=file_get_contents(env('app_path').'key.txt');
$options->merchantPrivateKey = $yao;
$options->alipayCertPath = env('app_path').'alipayCertPublicKey_RSA2.crt';
$options->alipayRootCertPath = env('app_path').'alipayRootCert.crt';
$options->merchantCertPath = env('app_path').'appCertPublicKey_xxxx.crt';
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
// $options->alipayPublicKey = '<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->';
//可设置异步通知接收服务地址(可选)
$options->notifyUrl = "https://xxxxx/index/test/notifyUrl";
//可设置AES密钥,调用AES加解密相关接口时需要(可选)
// $options->encryptKey = "<-- 请填写您的AES密钥,例如:aa4BtZ4tspm2wnXLb1ThQA== -->";
return $options;
}
public function pay_test(){
Factory::setOptions($this->getOptions());
try {
//2. 发起API调用(以支付能力下的统一收单交易创建接口为例)
$result = Factory::payment()->Wap()->pay("test", "20200326235526001", "0.01", "https://xxxxx/index/test/quitUrl",'https://xxxxx/index/test/returnurl');
$responseChecker = new ResponseChecker();
//3. 处理响应或异常
if ($responseChecker->success($result)) {
return $result->body;//重点 文档没说明,直接调用这个就跳出页面了
// return json($result);
} else {
echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
}
} catch (Exception $e) {
echo "调用失败,". $e->getMessage(). PHP_EOL;;
}
}