From 1ebbadba36478d4cc91c88dac46640d635253037 Mon Sep 17 00:00:00 2001
From: Anyon <zoujingli@qq.com>
Date: Wed, 27 Sep 2017 17:11:14 +0800
Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E8=BF=98=E5=8E=9Fload=5Fwe?=
 =?UTF-8?q?chat=E5=87=BD=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 application/common.php | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/application/common.php b/application/common.php
index 34f6737b2..5542e86d9 100644
--- a/application/common.php
+++ b/application/common.php
@@ -49,16 +49,25 @@ function mongo($col, $force = false)
  * @return \Wechat\WechatMedia|\Wechat\WechatMenu|\Wechat\WechatOauth|\Wechat\WechatPay|\Wechat\WechatReceive|\Wechat\WechatScript|\Wechat\WechatUser|\Wechat\WechatExtends|\Wechat\WechatMessage
  * @throws Exception
  */
-function load_wechat($name = '')
+function & load_wechat($type = '')
 {
-    static $cache = [];
-    if (empty($cache[$name])) {
-        list($appid, $appkey) = [sysconf('wechat_appid'), sysconf('wechat_appkey')];
-        $token = strtolower("{$name}-{$appid}-{$appkey}");
-        $location = "http://api.cuci.cc/wechat/instance/{$token}.html";
-        $cache[$name] = new SoapService(null, ['uri' => strtolower($name), 'location' => $location]);
+    static $wechat = [];
+    $index = md5(strtolower($type));
+    if (!isset($wechat[$index])) {
+        $config = [
+            'token'          => sysconf('wechat_token'),
+            'appid'          => sysconf('wechat_appid'),
+            'appsecret'      => sysconf('wechat_appsecret'),
+            'encodingaeskey' => sysconf('wechat_encodingaeskey'),
+            'mch_id'         => sysconf('wechat_mch_id'),
+            'partnerkey'     => sysconf('wechat_partnerkey'),
+            'ssl_cer'        => sysconf('wechat_cert_cert'),
+            'ssl_key'        => sysconf('wechat_cert_key'),
+            'cachepath'      => CACHE_PATH . 'wxpay' . DS,
+        ];
+        $wechat[$index] = Loader::get($type, $config);
     }
-    return $cache[$name];
+    return $wechat[$index];
 }
 
 /**