WxPaymethod.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\samos\wechat;
  3. use EasyWeChat\Factory;
  4. use app\model\Config;
  5. use app\model\Paymethod;
  6. class WxPaymethod
  7. {
  8. static public function makepay($ptype = 'wxapp')
  9. {
  10. if (empty($ptype)) {
  11. $ptype = 'wxapp';
  12. }
  13. if ($ptype == 'wxapp') {
  14. $app_id = Config::getconfig('miniprogram')['app_id'];
  15. } elseif ($ptype == 'mp') {
  16. $app_id = Config::getconfig('mp')['app_id'];
  17. }
  18. $wxpay_settings = Paymethod::getwx_settings();
  19. $app = Factory::payment([
  20. 'app_id' => trim($app_id),
  21. 'mch_id' => trim($wxpay_settings['mchid']),
  22. 'key' => trim($wxpay_settings['signkey']),
  23. 'cert_path' => dirname(dirname(dirname(__DIR__))) . trim($wxpay_settings['cert_path']), // XXX: 绝对路径!!!!
  24. 'key_path' => dirname(dirname(dirname(__DIR__))) . trim($wxpay_settings['key_path']) // XXX: 绝对路径!!!!
  25. ]);
  26. $appdata['lan'] = Author()::getlan();
  27. if ($wxpay_settings['service_pay'] == 1 && !empty(trim($wxpay_settings['sub_mch_id']))) {
  28. $app->setSubMerchant(trim($wxpay_settings['sub_mch_id']));
  29. }
  30. return $app;
  31. }
  32. static public function makepayv3($ptype = 'wxapp')
  33. {
  34. include dirname(dirname(dirname(__DIR__))) . '/extend/WeChatDeveloper/include.php';
  35. if (empty($ptype)) {
  36. $ptype = 'wxapp';
  37. }
  38. if ($ptype == 'wxapp') {
  39. $app_id = Config::getconfig('miniprogram')['app_id'];
  40. } elseif ($ptype == 'mp') {
  41. $app_id = Config::getconfig('mp')['app_id'];
  42. }
  43. $wxpay_settings = Paymethod::getwx_settings();
  44. $app = \WePayV3\Transfers::instance(
  45. [
  46. // 可选,公众号APPID
  47. 'appid' => trim($app_id),
  48. // 必填,微信商户编号ID
  49. 'mch_id' => trim($wxpay_settings['mchid']),
  50. // 必填,微信商户V3接口密钥
  51. 'mch_v3_key' => trim($wxpay_settings['signkeyv3']),
  52. // 可选,微信商户证书序列号,可从公钥中提取
  53. 'cert_serial' => '',
  54. // 必填,微信商户证书公钥,支持证书内容或文件路径
  55. 'cert_public' => dirname(dirname(dirname(__DIR__))) . trim($wxpay_settings['cert_path']),
  56. // 必填,微信商户证书私钥,支持证书内容或文件路径
  57. 'cert_private' => dirname(dirname(dirname(__DIR__))) . trim($wxpay_settings['key_path']),
  58. // 可选,运行时的文件缓存路径
  59. 'cache_path' => ''
  60. ]
  61. );
  62. $appdata['lan'] = Author()::getlan();
  63. return $app;
  64. }
  65. }