Pay.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\pay;
  12. use app\dict\pay\PayDict;
  13. use think\facade\Lang;
  14. use think\Validate;
  15. /**
  16. * Class Pay
  17. * @package app\validate\pay
  18. */
  19. class Pay extends Validate
  20. {
  21. //用户名或密码的规范可能是从数据库中获取的
  22. protected $rule = [
  23. //支付宝
  24. 'app_id' => 'requireIf:type,' . PayDict::ALIPAY,
  25. 'app_secret_cert' => 'requireIf:type,' . PayDict::ALIPAY,
  26. 'app_public_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  27. 'alipay_public_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  28. 'alipay_root_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  29. //微信
  30. 'mch_id' => 'requireIf:type,' . PayDict::WECHATPAY,
  31. 'mch_secret_key' => 'requireIf:type,' . PayDict::WECHATPAY,
  32. 'mch_secret_cert' => 'requireIf:type,' . PayDict::WECHATPAY,
  33. 'mch_public_cert_path' => 'requireIf:type,' . PayDict::WECHATPAY,
  34. //支付方式
  35. 'type' => 'require|checkPayType',
  36. ];
  37. protected $message = [
  38. 'app_id.requireIf' => 'validate_pay.app_id_requireif',
  39. 'app_secret_cert.requireIf' => 'validate_pay.app_secret_cert_requireif',
  40. 'app_public_cert_path.requireIf' => 'validate_pay.app_public_cert_path_requireif',
  41. 'alipay_public_cert_path.requireIf' => 'validate_pay.alipay_public_cert_path_requireif',
  42. 'alipay_root_cert_path.requireIf' => 'validate_pay.alipay_root_cert_path_requireif',
  43. 'mch_id.requireIf' => 'validate_pay.mch_id_requireif',
  44. 'mch_secret_key.requireIf' => 'validate_pay.mch_secret_key_requireif',
  45. 'mch_secret_cert.requireIf' => 'validate_pay.mch_secret_cert_requireif',
  46. 'mch_public_cert_path.requireIf' => 'validate_pay.mch_public_cert_path_requireif',
  47. ];
  48. protected $scene = [
  49. 'set' => [
  50. // 'app_id', 'app_secret_cert', 'app_public_cert_path', 'alipay_public_cert_path', 'alipay_root_cert_path',
  51. // 'mch_id', 'mch_secret_key', 'mch_secret_cert', 'mch_public_cert_path',
  52. 'type',
  53. ],
  54. ];
  55. /**
  56. * 自定义验证 支付类型
  57. * @param $value
  58. * @param $rule
  59. * @param array $data
  60. * @return Lang|true
  61. */
  62. protected function checkPayType($value, $rule, $data = [])
  63. {
  64. return isset(PayDict::getPayType()[$value]) ? true : get_lang("validate_pay.not_exit_pay_type");
  65. }
  66. }