Update WechatService.php

This commit is contained in:
Anyon 2019-07-17 11:34:42 +08:00
parent 6b1542c22b
commit bf528436e2

View File

@ -128,11 +128,13 @@ class WechatService extends \We
public static function instance($name, $type = 'WeChat', $config = []) public static function instance($name, $type = 'WeChat', $config = [])
{ {
if (!in_array($type, ['WeChat', 'WeMini', 'WePay', 'AliPay'])) $type = self::$type; if (!in_array($type, ['WeChat', 'WeMini', 'WePay', 'AliPay'])) $type = self::$type;
if (self::getType() === 'api' || in_array($type, ['WePay', 'AliPay'])) { if (self::getType() === 'api' || in_array($type, ['WePay', 'AliPay']) || "{$type}{$name}" === 'WeChatPay') {
$class = "\\{$type}\\" . ucfirst(strtolower($name)); if (class_exists($class = "\\{$type}\\" . ucfirst(strtolower($name)))) {
if (class_exists($class)) return new $class(empty($config) ? self::config() : $config); return new $class(empty($config) ? self::config() : $config);
} else {
throw new \think\Exception("Class '{$class}' not found"); throw new \think\Exception("Class '{$class}' not found");
} }
} else {
set_time_limit(3600); set_time_limit(3600);
list($appid, $appkey) = [sysconf('wechat_thr_appid'), sysconf('wechat_thr_appkey')]; list($appid, $appkey) = [sysconf('wechat_thr_appid'), sysconf('wechat_thr_appkey')];
$token = strtolower("{$name}-{$appid}-{$appkey}-{$type}"); $token = strtolower("{$name}-{$appid}-{$appkey}-{$type}");
@ -142,9 +144,11 @@ class WechatService extends \We
if (class_exists('SoapClient')) { if (class_exists('SoapClient')) {
$location = config('wechat.service_url') . "/service/api.client/soap/{$token}"; $location = config('wechat.service_url') . "/service/api.client/soap/{$token}";
return new \SoapClient(null, ['uri' => strtolower($name), 'location' => $location]); return new \SoapClient(null, ['uri' => strtolower($name), 'location' => $location]);
} } else {
throw new \think\Exception("Yar or soap extensions are not installed."); throw new \think\Exception("Yar or soap extensions are not installed.");
} }
}
}
/** /**
* 获取微信网页JSSDK * 获取微信网页JSSDK