The v3 version is very different from the v2 version at the bottom level. The infrastructure has been redesigned to make it easier to expand and more convenient to use.
After developing Alipay and WeChat Pay many times, I naturally felt a sense of disgust and laziness came back. I wanted to look for related wheels online, but I never found one that I felt I was satisfied with, or it was too difficult to understand to use. Either the file structure is too messy, and you have to roll up your sleeves and do it yourself.
Welcome Star, welcome PR!
Please send hyperf extension package here
Please send laravel extension package here
Please send the yii expansion package here
Multi-tenant support
Swoole support
Flexible plug-in mechanism
Rich event system
Naming is less confusing
Hide details that developers don’t need to pay attention to
Developed based on the latest APIs of Alipay and WeChat
Highly abstract classes, eliminating the pain of spelling json and xml
The file structure is clear and easy to understand. You can add payment gateways that are not included in this project as you like.
Methods are more elegant to use, and you no longer have to study what those strange method names or class names are for.
There is a built-in method to automatically obtain the WeChat public certificate, so you no longer have to worry about obtaining the certificate for the first time.
Complying with PSR2, PSR3, PSR4, PSR7, PSR11, PSR14, PSR18 and other standards, you can easily integrate with your framework
https://pay.yansongda.cn/docs/v3/overview/planning
https://pay.yansongda.cn
yansongda/pay is 100% compatible with all functions of Alipay/WeChat/UnionPay (including service provider functions) and can be introduced through the "plug-in mechanism".
At the same time, the SDK directly supports the following built-in plug-ins. Please refer to the documentation for details.
Computer payment
Mobile website payment
APP payment
Pay by card
Scan code to pay
Account transfer
Mini program payment
...
Official account payment
Mini program payment
H5 payment
Scan code to pay
APP payment
Pay by card
...
Mini program payment
...
Mobile website payment
Computer website payment
Pay by card
Scan code to pay
...
Integrated scan code payment (WeChat, Alipay, UnionPay, e-finance)
...
composer require yansongda/pay:~3.7.0 -vvv
<?phpnamespace AppHttpControllers;use YansongdaPayPay;class AlipayController {protected $config = ['alipay' => ['default' => [// Required - app_id assigned by Alipay 'app_id' => '2016082000295641', // Required - application private key string or path 'app_secret_cert ' => '89iZ2iC16H6/6a3YcP+hDZUjiNGQx9cuwi9eJyykvcwhD...',// Required - application public key certificate path 'app_public_cert_path' => '/Users/yansongda/pay/cert/appCertPublicKey_2016082000295641.crt',// Required - Alipay public key certificate path 'alipay_public_cert_path' => '/Users/yansongda/pay/cert/alipayCertPublicKey_RSA2.crt',// Required - Alipay root certificate path 'alipay_root_cert_path' => '/Users/yansongda/pay/ cert/alipayRootCert.crt','return_url' => 'https://yansongda.cn/alipay/return','notify_url' => 'https://yansongda.cn/alipay/notify',// Optional - third-party application authorization token 'app_auth_token' => '' ,// Optional - the service provider id in service provider mode, use this parameter 'service_provider_id' => when the mode is Pay::MODE_SERVICE '',// Optional - defaults to normal mode. Optional options are: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE'mode' => Pay::MODE_NORMAL, ], ], 'logger' => [ // optional'enable' => false,'file' => './logs/alipay.log','level' => 'info', // It is recommended that the production environment level be adjusted to info, the development environment is debug 'type' => 'single', // optional, optional daily.'max_file' => 30, // optional, valid when type is daily, default 30 days], 'http' = > [ // optional'timeout' => 5.0,'connect_timeout' => 5.0, // For more configuration items, please refer to [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)] , ];public function web() { Pay::config($this->config); $result = Pay::alipay()->web(['out_trade_no' => ''.time(),'total_amount' => '0.01','subject' => 'yansongda test-1', ]); return $result; }public function returnCallback() { Pay::config($this->config); $data = Pay::alipay()->callback(); // Yes, signature verification is that simple! // Order number: $data->out_trade_no// Alipay transaction number: $data->trade_no// Total order amount: $data->total_amount} public function notifyCallback() { Pay::config($this->config); try{$data = Pay::alipay()->callback(); // Yes, signature verification is that simple! // Please make your own judgment on trade_status and other logic. In Alipay's business notification, Alipay will consider the buyer's payment successful only when the transaction notification status is TRADE_SUCCESS or TRADE_FINISHED. // 1. The merchant needs to verify whether out_trade_no in the notification data is the order number created in the merchant system; // 2. Determine whether the total_amount is indeed the actual amount of the order (that is, the amount when the merchant order was created); // 3 , Verify the seller_id (or seller_email) in the notification Whether it is the corresponding operator of the out_trade_no document (sometimes, a merchant may have multiple seller_id/seller_email); // 4. Verify whether the app_id is the merchant itself. // 5. Other business logic situations} catch (Throwable $e) {dd($e); }return Pay::alipay()->success(); } }
<?phpnamespace AppHttpControllers;use YansongdaPayPay;class WechatController {protected $config = ['wechat' => ['default' => [// Required - merchant number 'mch_id' => '', // Optional - v2 merchant private key 'mch_secret_key_v2' => '', // Required - v3 merchant secret key 'mch_secret_key' => '', // Required - Merchant private key String or path 'mch_secret_cert' => '',// Required - merchant public key certificate path 'mch_public_cert_path' => '',// Required 'notify_url' => 'https://yansongda.cn/wechat/ notify',// Optional - the app_id of the official account 'mp_app_id' => '',// Optional - the app_id of the mini program app_id'mini_app_id' => '',// Optional - the app_id of the app 'app_id' => '',// Optional - the app_id of the sub-official account in service provider mode 'sub_mp_app_id' => '',// Optional - In service provider mode, the app_id of the sub-app 'sub_app_id' => '', // Optional - In service provider mode, the app_id of the sub-app app_id'sub_mini_app_id' => '',// Optional - In service provider mode, sub-merchant id'sub_mch_id' => '',// Optional - WeChat platform public key certificate path, optional, php-fpm mode is strongly recommended Configure this parameter under 'wechat_public_cert_path' => ['45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatpay_45F***D57.pem', ], // Optional - defaults to normal mode. Optional options are: MODE_NORMAL, MODE_SERVICE'mode' => Pay::MODE_NORMAL, ] ],'logger' => [ // optional'enable' => false,'file' => './logs/wechat.log','level' => 'info', // It is recommended that the production environment level be adjusted to info, the development environment is debug 'type' => 'single', // optional, optional daily.'max_file' => 30, // optional, valid when type is daily, default 30 days], 'http' = > [ // optional'timeout' => 5.0,'connect_timeout' => 5.0, // For more configuration items, please refer to [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)] , ];public function index() { Pay::config($this->config); $order = ['out_trade_no' => time().'','description' => 'subject-test','amount' => [ 'total' => 1, ],'payer' => [ 'openid' => 'onkVf1FjWS5SBxxxxxxxx', ], ];$pay = Pay::wechat()->mp($order);// $pay->appId// $pay->timeStamp// $pay->nonceStr// $pay->package// $ pay->signType}public function callback() { Pay::config($this->config); try{$data = Pay::wechat()->callback(); // Yes, signature verification is that simple! } catch (Throwable $e) {dd($e); } return Pay::wechat()->success(); } }
<?phpnamespace AppHttpControllers;use YansongdaPayPay;class DouyinController {protected $config = ['douyin' => ['default' => [// Optional-merchant number // Douyin Open Platform --> Application details --> Payment information --> Product management --> Merchant No. 'mch_id' => '73744242495132490630', // Required - Payment Token, used for payment callback signature // Douyin Open Platform --> Application details --> Payment information --> Payment settings --> Token (token) 'mch_secret_token' => 'douyin_mini_token', // Required - Payment SALT, used for payment signature // Douyin Open Platform --> Application details --> Payment information --> Payment settings --> SALT'mch_secret_salt' => 'oDxWDBr4U7FAAQ8hnGDm29i4A6pbTMDKme4WLLvA',//Required - Mini Program app_id// Douyin Open Platform --> Application details --> Payment information --> Payment settings --> Mini program appid 'mini_app_id' => 'tt226e54d3bd581bf801',// Optional - Douyin open platform service provider id 'thirdparty_id' => '', // Optional - Douyin payment callback address 'notify_url' => 'https://yansongda.cn/douyin/notify', ], ],'logger' => [ // optional'enable' => false,'file' => './logs/alipay.log','level' => 'info', // It is recommended that the production environment level be adjusted to info, the development environment is debug 'type' => 'single', // optional, optional daily.'max_file' => 30, // optional, valid when type is daily, default 30 days], 'http' = > [ // optional'timeout' => 5.0,'connect_timeout' => 5.0, // For more configuration items, please refer to [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)] , ];public function pay() { Pay::config($this->config); $result = Pay::douyin()->mini(['out_order_no' => date('YmdHis').mt_rand(1000, 9999),'total_amount' => 1,'subject' => 'Yan Songda- test - subject - 01','body' => 'Yan Songda - test - body - 01','valid_time' => 600,'expand_order_info' => json_encode(['original_delivery_fee' => 15,'actual_delivery_fee' => 10]) ]); return $result; }public function callback() { Pay::config($this->config); try{$data = Pay::douyin()->callback(); // Yes, signature verification is that simple! } catch (Throwable $e) {dd($e) }return Pay::douyin()->success(); } }
<?phpnamespace AppHttpControllers;use YansongdaPayPay;class JsbController {protected $config = ['jsb' => ['default' => [// Service code 'svr_code' => '',// Required - Partner ID 'partner_id' => '',// Required -Public and private key pair number 'public_key_code' => '00', // Required - Merchant private key (encrypted signature) 'mch_secret_cert_path' => '',//Required-Merchant public key certificate path (provided by Jiangsu Bank for signature verification)'mch_public_cert_path' => '',//Required-Jiangsu Bank's public key (used to decrypt the data returned by Jiangsu Bank) 'jsb_public_cert_path' => '', //Payment notification address 'notify_url' => '', // Optional - the default is normal mode. Optional options are: MODE_NORMAL: official environment, MODE_SANDBOX: test environment 'mode' => Pay::MODE_NORMAL, ] ],'logger' => [ // optional'enable' => false,'file' => './logs/epay.log','level' => 'info', // It is recommended that the production environment level be adjusted to info, the development environment is debug 'type' => 'single', // optional, optional daily.'max_file' => 30, // optional, valid when type is daily, default 30 days], 'http' = > [ // optional'timeout' => 5.0,'connect_timeout' => 5.0, // For more configuration items, please refer to [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)] , ];public function index() { Pay::config($this->config); $order = ['outTradeNo' => time().'','proInfo' => 'subject-test','totalFee'=> 1, ];$pay = Pay::jsb()->scan($order); }public function notifyCallback() { Pay::config($this->config);try{$data = Pay::jsb()->callback(); // Yes, signature verification is that simple! } catch (Throwable $e) {dd($e); } return Pay::jsb()->success(); } }
Due to the limitations of the testing and usage environment, only the relevant payment gateways of "Alipay", "WeChat Pay", "Douyin Pay", "UnionPay" and "Jiangsu Bank" were developed in this project.
If you have needs for other payment gateways, or find code that needs improvement in this project, you are welcome to Fork and submit a PR!
MIT