64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			64 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
|  | <?php | |||
|  | 
 | |||
|  | namespace app\service; | |||
|  | 
 | |||
|  | use Yansongda\Pay\Pay; | |||
|  | use Yansongda\Pay\Log; | |||
|  | use think\facade\Config; | |||
|  | 
 | |||
|  | class Alipay | |||
|  | { | |||
|  |     private static $app = null; | |||
|  | 
 | |||
|  |     private function __construct() | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     private function __clone() | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     /** | |||
|  |      * 支付宝配置 | |||
|  |      * | |||
|  |      * @return array | |||
|  |      */ | |||
|  |     public static function config(): array | |||
|  |     { | |||
|  |         Config::load('extra/alipay', 'alipay'); | |||
|  |         $conf = config('alipay'); | |||
|  |         return [ | |||
|  |             'app_id'         => trim($conf['appId']), | |||
|  |             'notify_url'     => trim($conf['notify_url']), | |||
|  |             'return_url'     => trim($conf['return_url']) ?? trim($conf['notify_url']), | |||
|  |             'ali_public_key' => trim($conf['aliPubKey']),//注意 这里的是支付宝的公钥
 | |||
|  |             // 加密方式: **RSA2**
 | |||
|  |             'private_key'    => trim($conf['priKey']), | |||
|  |             // 使用公钥证书模式,请配置下面两个参数,同时修改ali_public_key为以.crt结尾的支付宝公钥证书路径,
 | |||
|  |             // 如(./cert/alipayCertPublicKey_RSA2.crt)
 | |||
|  |             // 'app_cert_public_key' => './cert/appCertPublicKey.crt', //应用公钥证书路径
 | |||
|  |             // 'alipay_root_cert' => './cert/alipayRootCert.crt', //支付宝根证书路径
 | |||
|  |             'log'            => [ // optional
 | |||
|  |                 'file'     => './logs/alipay.log', | |||
|  |                 'level'    => 'debug', // 建议生产环境等级调整为 info,开发环境为 debug
 | |||
|  |                 'type'     => 'single', // optional, 可选 daily.
 | |||
|  |                 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
 | |||
|  |             ], | |||
|  |             'http'           => [ // optional
 | |||
|  |                 'timeout'         => 5.0, | |||
|  |                 'connect_timeout' => 5.0, | |||
|  |                 // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
 | |||
|  |             ], | |||
|  |             //                'mode' => 'dev', // optional,设置此参数,将进入沙箱模式
 | |||
|  |         ]; | |||
|  |     } | |||
|  | 
 | |||
|  |     //支付宝支付实例  单例模式
 | |||
|  |     public static function getInstance(): ?\Yansongda\Pay\Gateways\Alipay | |||
|  |     { | |||
|  |         if (self::$app == null) { | |||
|  |             self::$app = Pay::alipay(self::config()); | |||
|  |         } | |||
|  |         return self::$app; | |||
|  |     } | |||
|  | } |