Identify.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Certify.php UTF-8
  4. * 实名认证接口驱动
  5. *
  6. * @date : 2019/12/2 16:32
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.5
  11. */
  12. namespace huoIdentify\identifyDriver;
  13. use huolib\constant\IdentifyConst;
  14. use huolib\status\IdentifyStatus;
  15. use think\Exception;
  16. use think\Log;
  17. class Identify {
  18. static $ins;
  19. private $identify_from
  20. = [
  21. 'default' => IdentifyConst::DRIVER_NAME_ALIPAY,
  22. IdentifyConst::DRIVER_KEY_ALIPAY => IdentifyConst::DRIVER_NAME_ALIPAY,
  23. IdentifyConst::DRIVER_KEY_WXPAY => IdentifyConst::DRIVER_NAME_WXPAY,
  24. IdentifyConst::DRIVER_KEY_FCMGAME => IdentifyConst::DRIVER_NAME_FCMGAME,
  25. IdentifyConst::DRIVER_KEY_YIWAN => IdentifyConst::DRIVER_NAME_YIWAN,
  26. IdentifyConst::DRIVER_KEY_HUOUNION => IdentifyConst::DRIVER_NAME_HUOUNION,
  27. IdentifyConst::DRIVER_KEY_GUOPAN => IdentifyConst::DRIVER_NAME_GUOPAN,
  28. IdentifyConst::DRIVER_KEY_JUEFENG => IdentifyConst::DRIVER_NAME_JUEFENG,
  29. IdentifyConst::DRIVER_KEY_QIANXI => IdentifyConst::DRIVER_NAME_QIANXI,
  30. IdentifyConst::DRIVER_KEY_YIXIN => IdentifyConst::DRIVER_NAME_YIXIN,
  31. IdentifyConst::DRIVER_KEY_LIEBAO => IdentifyConst::DRIVER_NAME_LIEBAO,
  32. IdentifyConst::DRIVER_KEY_TIANYU => IdentifyConst::DRIVER_NAME_TIANYU,
  33. IdentifyConst::DRIVER_KEY_KUCHANG => IdentifyConst::DRIVER_NAME_KUCHANG,
  34. IdentifyConst::DRIVER_KEY_MOXING => IdentifyConst::DRIVER_NAME_MOXING,
  35. IdentifyConst::DRIVER_KEY_HUANJUYOU => IdentifyConst::DRIVER_NAME_HUANJUYOU,
  36. IdentifyConst::DRIVER_KEY_HAIQUYOU => IdentifyConst::DRIVER_NAME_HAIQUYOU,
  37. ];
  38. public static function ins() {
  39. if (self::$ins == null) {
  40. self::$ins = new self();
  41. }
  42. return self::$ins;
  43. }
  44. /**
  45. * @param string $identify_from
  46. * @param array $config
  47. *
  48. * @return mixed
  49. * @throws Exception
  50. */
  51. public function get($identify_from = '', $config = []) {
  52. if (empty($identify_from)) {
  53. return $this->register('default');
  54. }
  55. $_pay_obj = $this->register($identify_from, $config);
  56. if (!isset($_pay_obj)) {
  57. Log::write(
  58. "func=".__FUNCTION__."&class=".__CLASS__."&errmsg=registerError&identify_from=".$identify_from
  59. .'objName='.$this->identify_from[$identify_from], 'info'
  60. );
  61. $_code = IdentifyStatus::IDENTIFY_FROM_INCORRECT;
  62. throw new Exception(IdentifyStatus::getMsg($_code), $_code);
  63. }
  64. return $_pay_obj;
  65. }
  66. /**
  67. * @param string $identify_from
  68. * @param array $config
  69. *
  70. * @return Driver
  71. */
  72. protected function register($identify_from = '', $config = []) {
  73. $identify_from = strtolower($identify_from);
  74. $_class = '\\huoIdentify\\identifyDriver\\driver\\'.$this->identify_from[$identify_from];
  75. return new $_class($config);
  76. }
  77. }