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->notifyUrl = "https://xxxxx/index/test/notifyUrl";
return $options;
}
public function pay_test(){
Factory::setOptions($this->getOptions());
try {
$result = Factory::payment()->Wap()->pay("test", "20200326235526001", "0.01", "https://xxxxx/index/test/quitUrl",'https://xxxxx/index/test/returnurl');
$responseChecker = new ResponseChecker();
if ($responseChecker->success($result)) {
return $result->body;
} else {
echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
}
} catch (Exception $e) {
echo "调用失败,". $e->getMessage(). PHP_EOL;;
}
}
|