You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.1 KiB

5 years ago
<?php
namespace App\Libs;
use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Kernel\Util\ResponseChecker;
use Alipay\EasySDK\Kernel\Config;
5 years ago
use Illuminate\Support\Facades\Log;
5 years ago
class AlipayF2F
{
public function test()
{
try {
$auth_code = request()->auth_code;
5 years ago
$result = Factory::setOptions($this->getOptions())::payment()->faceToFace("这是一个测试商品", time(), "0.1", $auth_code);
5 years ago
$responseChecker = new ResponseChecker();
//处理响应或异常
if ($responseChecker->success($result)) {
5 years ago
Log::info(serialize($result));
5 years ago
return [
"status" => true
];
} else {
return [
"status" => false,
"code" => $result->code,
"msg" => $result->msg
];
}
} catch (\Exception $exception) {
return [
"status" => false,
"code" => $exception->getCode(),
"msg" => $exception->getMessage()
];
}
}
public function getOptions()
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->signType = 'RSA2';
$options->appId = env("ALI_APP_ID");
$options->alipayCertPath = env("ALI_CERT_ALIPAY");
$options->alipayRootCertPath = env("ALI_CERT_ROOT");
$options->merchantCertPath = env("ALI_CERT_APP");
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = env("ALI_PRIVATE_KEY");
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
$options->alipayPublicKey = env("ALI_PUBLIC_KEY");
//可设置异步通知接收服务地址(可选)
$options->notifyUrl = "";
//可设置AES密钥调用AES加解密相关接口时需要可选
$options->encryptKey = "";
return $options;
}
}