title('支付配置') // ->body($this->buildPreviewButton()) // ->body($this->newline()) ->body( <<{$this->form_pay()->render()} HTML ); } protected function form_pay(){ $form = new Form(); $form->confirm('您确定要提交表单吗?', 'content'); $form->disableResetButton(); $form->tab('开关', function (Form $form) { $form->html(function () { return '
提示: 小程序内必须使用小程序支付,所以不用选择。
'; }, ''); $form->radio('app_app_pay_type_wechat', '微信')->help('App内微信的支付方式')->options(['close' => '关闭', 'app'=>'app', 'h5'=>'h5', 'yi'=>'yi'])->default(Settings::get('app_app_pay_type_wechat', 'app')); $form->radio('app_app_pay_type_ali', '支付宝')->help('App内支付宝的支付方式')->options(['close' => '关闭', 'app'=>'app', 'h5'=>'h5', 'yi'=>'yi'])->default(Settings::get('app_app_pay_type_ali', 'app')); $form->radio('app_app_pay_type_apple', '苹果内购')->help('IOS是否开启苹果内购,若开启了审核模式,则会强制开启')->options(['close' => '关闭', 'open'=>'开启'])->default(Settings::get('app_app_pay_type_apple', 'close')); $form->divider(); $form->html(function () { return '
提示: ios系统微信小程序不允许虚拟产品的购买,所以你可以设置是否采用公众号支付来替代。
'; }, ''); $form->switch('mini_ios_virtual_products_mp_pay', '虚拟产品开启公众号支付')->help('需要你配置好公众号的服务器链接[全局配置-支付-微信-公众号],且配置好h5端的域名[全局配置-常规-h5端]')->default(Settings::get('mini_ios_virtual_products_mp_pay', 0)); }); $form->tab('微信', function (Form $form) { $form->html(function () { return ''; }, '一、微信小程序'); $form->text('app_id', 'AppID')->help('前往:https://mp.weixin.qq.com/')->default(Settings::get('app_id', '')); $form->text('app_meta_appid', '原始ID')->help('前往:https://mp.weixin.qq.com/,注意这个是原始ID,类似:gh_31aec555bf2f,这个不填,分享到微信聊天则使用普通图文分享,如果这里配置了,则使用小程序专属分享,点击查看查找位置')->default(Settings::get('app_meta_appid', '')); $form->password('app_secret', 'AppSecret')->help('前往:https://mp.weixin.qq.com/')->default(Settings::get('app_secret', '')); $form->html(function () { return '
* 小程序 消息推送: 服务器地址: '.env('APP_URL').'/api/v1/wechat/mini/event
查看配置示例教程
'; }, ''); $form->text('app_message_token', 'Token')->default(Settings::get('app_message_token', '')); $form->text('app_message_aes_key', 'EncodingAESKey')->default(Settings::get('app_message_aes_key', '')); $form->switch('need_mini_deliver_info_manage', '对接《发货信息管理》')->default(Settings::get('need_mini_deliver_info_manage', 0)); $form->divider(); $form->html(function () { return ''; }, '二、公众号'); $form->text('mp_app_id', 'AppID')->help('前往:https://mp.weixin.qq.com/')->default(Settings::get('mp_app_id', '')); $form->password('mp_app_secret', 'AppSecret')->help('前往:https://mp.weixin.qq.com/')->default(Settings::get('mp_app_secret', '')); $form->text('mp_app_name', '公众号名称')->default(Settings::get('mp_app_name', '')); $form->html(function () { return '
* 公众号 消息推送:服务器地址: '.env('APP_URL').'/api/v1/wechat/mp/event
查看配置示例教程
'; }, ''); $form->text('mp_app_token', 'Token')->default(Settings::get('mp_app_token', '')); $form->text('mp_app_aes_key', 'EncodingAESKey')->default(Settings::get('mp_app_aes_key', '')); $form->divider(); $form->html(function () { return ''; }, '三、App移动应用'); $form->html(function () { return '
应用签名教程: https://doc.minisns.cn/doc/141/
'; }, ''); $form->text('app_app_id', 'AppID')->help('前往:https://open.weixin.qq.com/')->default(Settings::get('app_app_id', '')); $form->password('app_app_secret', 'AppSecret')->help('前往:https://open.weixin.qq.com/')->default(Settings::get('app_app_secret', '')); $form->divider(); $form->html(function () { return ''; }, '四、网站应用'); $form->text('web_app_id', 'AppID')->help('前往:https://open.weixin.qq.com/')->default(Settings::get('web_app_id', '')); $form->password('web_app_secret', 'AppSecret')->help('前往:https://open.weixin.qq.com/')->default(Settings::get('web_app_secret', '')); $form->divider(); $form->html(function () { return ''; }, '五、微信商户'); $form->text('mch_id', '商户号')->help('前往:https://pay.weixin.qq.com/')->default(Settings::get('mch_id', '')); $form->password('mch_secret', '商户密钥')->help('区别于私钥,一字之隔,自己在微信商家后台自定义的32位。前往:https://pay.weixin.qq.com/,请把v2版本和v3版本都设置且保持一致,新版本已更换为v3接口')->default(Settings::get('mch_secret', '')); $form->textarea('mch_cert_client', '商户公钥')->help('必选,可在 账户中心->API安全->申请API证书 里获得(apiclient_cert.pem)')->default(Settings::get('mch_cert_client', '')); $form->textarea('mch_cert_key', '商户私钥')->help('必选,账户中心->API安全->申请API证书 里获得(apiclient_key.pem)')->default(Settings::get('mch_cert_key', '')); $form->switch('mch_transfer_to_weChat', '《商家转账到零钱》')->help('产品是否开通')->default(Settings::get('mch_transfer_to_weChat', 0)); }); $form->tab('支付宝', function (Form $form) { $form->text('ali_app_id', 'AppID')->help('前往:https://open.alipay.com/')->default(Settings::get('ali_app_id', null)); $form->html(function () { return '
1、首先你自己通过RSA签名验签工具,以证书的方式,生成一个公钥和私钥,私钥需要经过处理成PKCS1格式填到下面,公钥不用填
'; }, ''); $form->textarea('ali_private_key', '应用私钥')->help('处理成PKCS1格式教程')->default(Settings::get('ali_private_key', '')); $form->html(function () { return '
2、然后把生成的csr文件填在支付宝后台可以获得支付宝公钥等三个证书,将证书以“记事本”打开,复制里面的内容到对应的框框里
'; }, ''); $form->textarea('ali_my_publish_key', '应用公钥')->help('三个证书说明')->default(Settings::get('ali_my_publish_key', '')); $form->textarea('ali_public_key', '支付宝公钥')->default(Settings::get('ali_public_key', null)); $form->textarea('ali_root_key', '支付宝根证书')->default(Settings::get('ali_root_key', null)); $form->switch('ali_transfer_to_rest', '《转账到支付宝账户》')->help('产品是否开通')->default(Settings::get('ali_transfer_to_rest', 0)); }); $form->tab('苹果', function (Form $form) { $form->text('apple_pay_password', 'App共享密码')->help('点击查看')->placeholder('4bd0b352aef2445ae34a895468c1747f')->default(Settings::get('apple_pay_password', '')); }); $form->tab('易支付', function (Form $form) { $form->text('yi_app_id', '商户ID')->help('前往:https://pay.minisns.cn/查看教程')->default(Settings::get('yi_app_id', null)); $form->text('yi_app_secret', '商户密钥')->default(Settings::get('yi_app_secret', null)); $form->text('yi_provider_url', '接口api')->default(Settings::get('yi_provider_url', 'https://pay.minisns.cn')); }); $form->action('settings/action/pay'); return $form; } public function pay(Request $request){ if($request->input('need_mini_deliver_info_manage', 0) == 1){ $weapp = new WeApp('mini'); $manage = $weapp->getDeliverInfoManage(); if(!$manage->isNeed()){ return $this->response()->error('你的小程序无需开启《发货信息管理》!'); } } SiteUtils::forget_config_data(); Settings::set('app_app_pay_type_wechat', $request->input('app_app_pay_type_wechat'), true); Settings::set('app_app_pay_type_ali', $request->input('app_app_pay_type_ali'), true); Settings::set('app_app_pay_type_apple', $request->input('app_app_pay_type_apple'), true); Settings::set('mini_ios_virtual_products_mp_pay', $request->input('mini_ios_virtual_products_mp_pay') == 1 ? 1 : 0, true); Settings::set('app_id', $request->input('app_id'), true); Settings::set('app_meta_appid', $request->input('app_meta_appid'), true); Settings::set('app_secret', $request->input('app_secret')); Settings::set('mp_app_id', $request->input('mp_app_id'), true); Settings::set('mp_app_secret', $request->input('mp_app_secret')); Settings::set('mp_app_name', $request->input('mp_app_name')); Settings::set('mp_app_token', $request->input('mp_app_token')); Settings::set('mp_app_aes_key', $request->input('mp_app_aes_key')); Settings::set('app_message_token', $request->input('app_message_token')); Settings::set('app_message_aes_key', $request->input('app_message_aes_key')); Settings::set('web_app_id', $request->input('web_app_id'), true); Settings::set('web_app_secret', $request->input('web_app_secret')); Settings::set('app_app_id', $request->input('app_app_id'), true); Settings::set('app_app_secret', $request->input('app_app_secret')); Settings::set('mch_id', $request->input('mch_id'), true); Settings::set('mch_secret', $request->input('mch_secret')); Settings::set('mch_cert_client', $request->input('mch_cert_client')); Settings::set('mch_cert_key', $request->input('mch_cert_key')); Settings::set('mch_transfer_to_weChat', $request->input('mch_transfer_to_weChat', 0) == 1 ? 1 : 0, true); Settings::set('need_mini_deliver_info_manage', $request->input('need_mini_deliver_info_manage', 0) == 1 ? 1 : 0, true); //支付宝 Settings::set('ali_app_id', $request->input('ali_app_id'), true); Settings::set('ali_public_key', $request->input('ali_public_key'), true); Settings::set('ali_root_key', $request->input('ali_root_key'), true); Settings::set('ali_transfer_to_rest', $request->input('ali_transfer_to_rest') == 1 ? 1 : 0, true); Settings::set('ali_private_key', $request->input('ali_private_key')); Settings::set('ali_my_publish_key', $request->input('ali_my_publish_key')); Settings::set('apple_pay_password', $request->input('apple_pay_password'), true); //易支付 Settings::set('yi_app_id', $request->input('yi_app_id'), true); Settings::set('yi_app_secret', $request->input('yi_app_secret')); Settings::set('yi_provider_url', $request->input('yi_provider_url'), true); $yi_pay_config = [ 'app_id' => $request->input('yi_app_id'), 'app_secret' => $request->input('yi_app_secret'), 'provider_url'=> $request->input('yi_provider_url'), 'site' => Settings::get('app_title'), 'notify_url' => env('APP_URL'). '/api/v1/app/yi/notify', 'return_url' => env('APP_URL') ]; Cache::forget('yi_pay_config'); Cache::put('yi_pay_config', json_encode($yi_pay_config)); $app_pay_config = [ 'alipay' => [ 'default' => [ // 必填-支付宝分配的 app_id 'app_id' => $request->input('ali_app_id'), // 必填-应用私钥 字符串或路径 // 在 https://open.alipay.com/develop/manage 《应用详情->开发设置->接口加签方式》中设置 'app_secret_cert' => $request->input('ali_private_key', ''), // 必填-应用公钥证书 路径 // 设置应用私钥后,即可下载得到以下3个证书 'app_public_cert_path' => storage_path('app/certs/alipay/appCertPublicKey.crt'), // 必填-支付宝公钥证书 路径 'alipay_public_cert_path' => storage_path('app/certs/alipay/alipayCertPublicKey_RSA2.crt'), // 必填-支付宝根证书 路径 'alipay_root_cert_path' => storage_path('app/certs/alipay/alipayRootCert.crt'), 'return_url' => env('APP_URL'), 'notify_url' => env('APP_URL'). '/api/v1/app/ali/notify/app', // 选填-第三方应用授权token 'app_auth_token' => '', // 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数 'service_provider_id' => '', // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE 'mode' => Pay::MODE_NORMAL, ] ], 'wechat' => [ 'default' => [ // 必填-商户号,服务商模式下为服务商商户号 // 可在 https://pay.weixin.qq.com/ 账户中心->商户信息 查看 'mch_id' => $request->input('mch_id'), // 选填-v2商户私钥 'mch_secret_key_v2' => $request->input('mch_secret', ''), // 必填-v3 商户秘钥 // 即 API v3 密钥(32字节,形如md5值),可在 账户中心->API安全 中设置 'mch_secret_key' => $request->input('mch_secret', ''), // 必填-商户私钥 字符串或路径 // 即 API证书 PRIVATE KEY,可在 账户中心->API安全->申请API证书 里获得 // 文件名形如:apiclient_key.pem 'mch_secret_cert' => storage_path('app/certs/wechat/apiclient_key.pem'), // 必填-商户公钥证书路径 // 即 API证书 CERTIFICATE,可在 账户中心->API安全->申请API证书 里获得 // 文件名形如:apiclient_cert.pem 'mch_public_cert_path' => storage_path('app/certs/wechat/apiclient_cert.pem'), // 必填-微信回调url // 不能有参数,如?号,空格等,否则会无法正确回调 'notify_url' => env('APP_URL'). '/api/v1/app/wechat/notify', // 选填-公众号 的 app_id // 可在 mp.weixin.qq.com 设置与开发->基本配置->开发者ID(AppID) 查看 'mp_app_id' => $request->input('mp_app_id', ''), // 选填-小程序 的 app_id 'mini_app_id' => $request->input('app_id', ''), // 选填-app 的 app_id 'app_id' => $request->input('app_app_id', ''), // 选填-合单 app_id 'combine_app_id' => '', // 选填-合单商户号 'combine_mch_id' => '', // 选填-服务商模式下,子公众号 的 app_id 'sub_mp_app_id' => '', // 选填-服务商模式下,子 app 的 app_id 'sub_app_id' => '', // 选填-服务商模式下,子小程序 的 app_id 'sub_mini_app_id' => '', // 选填-服务商模式下,子商户id 'sub_mch_id' => '', // 选填-微信平台公钥证书路径, optional,强烈建议 php-fpm 模式下配置此参数 'wechat_public_cert_path' => [ // '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatPublicKey.crt', ], // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE 'mode' => Pay::MODE_NORMAL, ] ], 'unipay' => [ 'default' => [ // 必填-商户号 'mch_id' => '777290058167151', // 必填-商户公私钥 'mch_cert_path' => __DIR__.'/Cert/unipayAppCert.pfx', // 必填-商户公私钥密码 'mch_cert_password' => '000000', // 必填-银联公钥证书路径 'unipay_public_cert_path' => __DIR__.'/Cert/unipayCertPublicKey.cer', // 必填 'return_url' => 'https://yansongda.cn/unipay/return', // 必填 'notify_url' => 'https://yansongda.cn/unipay/notify', ], ], 'logger' => [ 'enable' => true, 'file' => storage_path('logs/pay.log'), 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug 'type' => 'daily', // optional, 可选 daily. 'max_file' => 5, // 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) ], ]; Cache::forget('app_pay_config'); Cache::put('app_pay_config', json_encode($app_pay_config)); _update_env([ "WECHATSERVICEACCOUNT_CLIENT_ID" => $request->input('mp_app_id', ''), "WECHATSERVICEACCOUNT_CLIENT_SECRET" => $request->input('mp_app_secret'), "WEIXIN_KEY" => $request->input('app_app_id', ''), "WEIXIN_SECRET" => $request->input('app_app_secret', ''), ]); $f1 = fopen(storage_path('app/certs/wechat/apiclient_key.pem'), 'w'); fwrite($f1, $request->input('mch_cert_key', '')); fclose($f1); $f2 = fopen(storage_path('app/certs/wechat/apiclient_cert.pem'), 'w'); fwrite($f2, $request->input('mch_cert_client', '')); fclose($f2); $f3 = fopen(storage_path('app/certs/alipay/appCertPublicKey.crt'), 'w'); fwrite($f3, $request->input('ali_my_publish_key', '')); fclose($f3); $f4 = fopen(storage_path('app/certs/alipay/alipayRootCert.crt'), 'w'); fwrite($f4, $request->input('ali_root_key', '')); fclose($f4); $f5 = fopen(storage_path('app/certs/alipay/alipayCertPublicKey_RSA2.crt'), 'w'); fwrite($f5, $request->input('ali_public_key', '')); fclose($f5); $__global_config_version__ = Settings::get('__global_config_version__', 1) + 1; Settings::set('__global_config_version__', $__global_config_version__); GatewayUtils::success('all', 13, [ 'version' => $__global_config_version__, 'file' => basename(__FILE__) ]); return $this->response()->success('成功!'); } }