Factory.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace Alipay\EasySDK\Kernel;
  3. use Alipay\EasySDK\Base\Image\Client as imageClient;
  4. use Alipay\EasySDK\Base\OAuth\Client as oauthClient;
  5. use Alipay\EasySDK\Base\Qrcode\Client as qrcodeClient;
  6. use Alipay\EasySDK\Base\Video\Client as videoClient;
  7. use Alipay\EasySDK\Marketing\OpenLife\Client as openLifeClient;
  8. use Alipay\EasySDK\Marketing\Pass\Client as passClient;
  9. use Alipay\EasySDK\Marketing\TemplateMessage\Client as templateMessageClient;
  10. use Alipay\EasySDK\Member\Identification\Client as identificationClient;
  11. use Alipay\EasySDK\Payment\App\Client as appClient;
  12. use Alipay\EasySDK\Payment\Common\Client as commonClient;
  13. use Alipay\EasySDK\Payment\FaceToFace\Client as faceToFaceClient;
  14. use Alipay\EasySDK\Payment\Huabei\Client as huabeiClient;
  15. use Alipay\EasySDK\Payment\Page\Client as pageClient;
  16. use Alipay\EasySDK\Payment\Wap\Client as wapClient;
  17. use Alipay\EasySDK\Security\TextRisk\Client as textRiskClient;
  18. use Alipay\EasySDK\Util\Generic\Client as genericClient;
  19. use Alipay\EasySDK\Util\AES\Client as aesClient;
  20. class Factory
  21. {
  22. public $config = null;
  23. public $kernel = null;
  24. private static $instance;
  25. protected static $base;
  26. protected static $marketing;
  27. protected static $member;
  28. protected static $payment;
  29. protected static $security;
  30. protected static $util;
  31. private function __construct($config)
  32. {
  33. if (!empty($config->alipayCertPath)) {
  34. $certEnvironment = new CertEnvironment();
  35. $certEnvironment->certEnvironment(
  36. $config->merchantCertPath,
  37. $config->alipayCertPath,
  38. $config->alipayRootCertPath
  39. );
  40. $config->merchantCertSN = $certEnvironment->getMerchantCertSN();
  41. $config->alipayRootCertSN = $certEnvironment->getRootCertSN();
  42. $config->alipayPublicKey = $certEnvironment->getCachedAlipayPublicKey();
  43. }
  44. $kernel = new EasySDKKernel($config);
  45. self::$base = new Base($kernel);
  46. self::$marketing = new Marketing($kernel);
  47. self::$member = new Member($kernel);
  48. self::$payment = new Payment($kernel);
  49. self::$security = new Security($kernel);
  50. self::$util = new Util($kernel);
  51. }
  52. public static function setOptions($config)
  53. {
  54. if (!(self::$instance instanceof self)) {
  55. self::$instance = new self($config);
  56. }
  57. return self::$instance;
  58. }
  59. private function __clone()
  60. {
  61. }
  62. public static function base()
  63. {
  64. return self::$base;
  65. }
  66. public static function marketing()
  67. {
  68. return self::$marketing;
  69. }
  70. public static function member()
  71. {
  72. return self::$member;
  73. }
  74. public static function payment()
  75. {
  76. return self::$payment;
  77. }
  78. public static function security()
  79. {
  80. return self::$security;
  81. }
  82. public static function util()
  83. {
  84. return self::$util;
  85. }
  86. }
  87. class Base
  88. {
  89. private $kernel;
  90. public function __construct($kernel)
  91. {
  92. $this->kernel = $kernel;
  93. }
  94. public function image()
  95. {
  96. return new imageClient($this->kernel);
  97. }
  98. public function oauth()
  99. {
  100. return new oauthClient($this->kernel);
  101. }
  102. public function qrcode()
  103. {
  104. return new qrcodeClient($this->kernel);
  105. }
  106. public function video()
  107. {
  108. return new videoClient($this->kernel);
  109. }
  110. }
  111. class Marketing
  112. {
  113. private $kernel;
  114. public function __construct($kernel)
  115. {
  116. $this->kernel = $kernel;
  117. }
  118. public function openLife()
  119. {
  120. return new openLifeClient($this->kernel);
  121. }
  122. public function pass()
  123. {
  124. return new passClient($this->kernel);
  125. }
  126. public function templateMessage()
  127. {
  128. return new templateMessageClient($this->kernel);
  129. }
  130. }
  131. class Member
  132. {
  133. private $kernel;
  134. public function __construct($kernel)
  135. {
  136. $this->kernel = $kernel;
  137. }
  138. public function identification()
  139. {
  140. return new identificationClient($this->kernel);
  141. }
  142. }
  143. class Payment
  144. {
  145. private $kernel;
  146. public function __construct($kernel)
  147. {
  148. $this->kernel = $kernel;
  149. }
  150. public function app()
  151. {
  152. return new appClient($this->kernel);
  153. }
  154. public function common()
  155. {
  156. return new commonClient($this->kernel);
  157. }
  158. public function faceToFace()
  159. {
  160. return new faceToFaceClient($this->kernel);
  161. }
  162. public function huabei()
  163. {
  164. return new huabeiClient($this->kernel);
  165. }
  166. public function page()
  167. {
  168. return new pageClient($this->kernel);
  169. }
  170. public function wap()
  171. {
  172. return new wapClient($this->kernel);
  173. }
  174. }
  175. class Security
  176. {
  177. private $kernel;
  178. public function __construct($kernel)
  179. {
  180. $this->kernel = $kernel;
  181. }
  182. public function textRisk()
  183. {
  184. return new textRiskClient($this->kernel);
  185. }
  186. }
  187. class Util
  188. {
  189. private $kernel;
  190. public function __construct($kernel)
  191. {
  192. $this->kernel = $kernel;
  193. }
  194. public function generic()
  195. {
  196. return new genericClient($this->kernel);
  197. }
  198. public function aes(){
  199. return new aesClient($this->kernel);
  200. }
  201. }