123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\common\library;
- use Alipay\EasySDK\Kernel\Factory;
- use Alipay\EasySDK\Kernel\Util\ResponseChecker;
- use app\common\model\Config;
- use think\Controller;
- class AliPay extends Controller
- {
- /*
- 配置参数
- */
- public function __construct()
- {
- // $this->appId = "2021003130678750";
- // $this->rsaPrivateKey = 'MIIEogIBAAKCAQEAuruxWS/zWEXuot2pNUyPGxrVXuLo+CLjp8s0Hrw+mHw0Z2rrJFhLm5Zh61jbXok/VWTo+BUeDmpV6yZhSHpFQAwjzXOj1LrsDTahc3Q1gRx/eEX7zl1jiW6exPFI2E61szsT8K63LVLGUnqXfAeonW3bGj5YCJ85pcb+D6XLsk2aArEM7ni0g2G/cbbBzFH20TPfiGVTP7QaXWFKJQiiRnWf5n52pAzXcSR8KHa+Jujrul1PC/XUro+0vtPKSTvECVkAV6FC1K3i7j2DHjD3jCz1afG/wu5jmW01iMhAWQDqYNZWZCANusyMwBlE1eimuc7eZZGQ3reSuXuNGnpaVwIDAQABAoIBAH4LJWnLORnzkmHy9z1X4Rztnur+hTzA6CQhwJuieyoYZJMOE4yj4N0zxALFJsYIJGzywWJ7dp9KXZZtgKsYhVf3Gc+baBG23pEIuDAjV94/qzc3HgIs/XwN5DORnpcLghBqJ0qF1HVOcznHMCtzS/h/564uOOQQ/iuNR36ubfF60f4yhwg5P+RE9UvsRYK6tLAd7oB8vRryeXGIJu1tlQI7QaKW9Gx5uOejgfXPFDC478PQssvZIuTJyvkEbY3p7GSFjgKUpQmXc+IVD5HWaLMpmpgseuORU467c5ZYgsIW9xtAHNl30tX1h6aSjMhLwW5O8cUzceFSSb+Pqo1MR8ECgYEA7S/qr+lj5akWYoS+lZtjgjrJaiLbg1Q7uiFKSJZyy61GMYaPJ2zE8VyGMZxvZXFhPgAgPzQ45/sbMvBYWozJ8UNbcbJEO3dxoPEmYQBI7j2AIgO+yg3cMPIB9D6z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6FC1K3i7j2DHjD3jCz1afG/wu5jmW01iMhAWQDqYNZWZCANusyMwBlE1eimuc7eZZGQ3reSuXuNGnpaVwIDAQAB';
- }
- /**
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * 支付宝支付
- */
- public static function ali_pay($subject,$totalAmount,$outTradeNo,$notifyUrl){
- Factory::setOptions(self::getOptions($notifyUrl));
- try {
- //2. 发起API调用(以支付能力下的统一收单交易创建接口为例)
- //$result = Factory::payment()->common()->create("iPhone6 16G", "20200326235526001", "88.88", "2088002656718920");
- $result = Factory::payment()->App()->pay($subject,$outTradeNo , $totalAmount);
- $responseChecker = new ResponseChecker();
- //3. 处理响应或异常
- if ($responseChecker->success($result)) {
- return $result->body;
- } else {
- echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
- }
- } catch (Exception $e) {
- return false;
- }
- }
- public static function ali_pay_pc($subject='商品',$totalAmount,$outTradeNo,$notifyUrl,$returnUrl){
- Factory::setOptions(self::getOptions($notifyUrl));
- try {
- $result = Factory::payment()->Page()->pay($subject,$outTradeNo,$totalAmount,$returnUrl);
- $responseChecker = new ResponseChecker();
- //3. 处理响应或异常
- if ($responseChecker->success($result)) {
- return $result->body;
- } else {
- echo "调用失败,原因:". $result->msg.",".$result->subMsg.PHP_EOL;
- }
- } catch (Exception $e) {
- return false;
- }
- }
- public static function getOptions($notifyUrl){
- $options = new \Alipay\EasySDK\Kernel\Config();
- $options->protocol = 'https';
- $options->gatewayHost = 'openapi.alipay.com';
- $options->signType = 'RSA2';
- $options->appId = '2021003130678750';
- // 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
- $options->merchantPrivateKey = 'MIIEogIBAAKCAQEAuruxWS/zWEXuot2pNUyPGxrVXuLo+CLjp8s0Hrw+mHw0Z2rrJFhLm5Zh61jbXok/VWTo+BUeDmpV6yZhSHpF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MuIlrndMqkpOaXgfNmSfACTTskflTuMiKTsOrdXQfk3V4fXK8pOTabKkCwO3gAQKBgCoLjeATi/ytsL0V6cKNlB4nZziC0OPCqVRccY7zoDRjiImL+qBRpN1J0l97SCXbJ0jd1R5zv3E5qvG4aBBeGqAp/PfYP69+1X92BTYkyONHPyCWHOCzuxyKYY2qkEn5zFxOzkXmD0Sjqd8nRqCTvAFlqAWIuxpBMduGPxaFQjXxAoGAD2SBY2eQ7OWwil91X4TgdKhWXMpCgqQChvqB/rFPK6L9264mM1DIwWc3w5Keu8c5tElRLnK2dJtof/Tu5vKf29DZA2egc2OZSXI9qQlyH7orubNLK2tXoH1/phvy+45K2rczmU6LnJQvcBzWjf32lLIdqZx6CI8Q/iY2gHgq4EI=';
- /*$options->alipayCertPath = '<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->';
- $options->alipayRootCertPath = '<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt" -->';
- $options->merchantCertPath = '<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->';*/
- //注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
- $options->alipayPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuruxWS/zWEXuot2pNUyPGxrVXuLo+CLjp8s0Hrw+mHw0Z2rrJFhLm5Zh61jbXok/VWTo+BUeDmpV6yZhSHpFQAwjzXOj1LrsDTahc3Q1gRx/eEX7zl1jiW6exPFI2E61szsT8K63LVLGUnqXfAeonW3bGj5YCJ85pcb+D6XLsk2aArEM7ni0g2G/cbbBzFH20TPfiGVTP7QaXWFKJQiiRnWf5n52pAzXcSR8KHa+Jujrul1PC/XUro+0vtPKSTvECVkAV6FC1K3i7j2DHjD3jCz1afG/wu5jmW01iMhAWQDqYNZWZCANusyMwBlE1eimuc7eZZGQ3reSuXuNGnpaVwIDAQAB';
- //可设置异步通知接收服务地址(可选)
- $options->notifyUrl = $notifyUrl;
- //可设置AES密钥,调用AES加解密相关接口时需要(可选)
- $options->encryptKey = "";
- return $options;
- }
- }
|