WechatService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/23
  6. */
  7. namespace crmeb\services;
  8. use app\admin\model\wechat\WechatMessage;
  9. use app\admin\model\wechat\WechatReply;
  10. use app\models\user\User;
  11. use app\models\user\WechatUser;
  12. use crmeb\repositories\MessageRepositories;
  13. use crmeb\repositories\PaymentRepositories;
  14. use EasyWeChat\Foundation\Application;
  15. use EasyWeChat\Message\Article;
  16. use EasyWeChat\Message\Image;
  17. use EasyWeChat\Message\Material;
  18. use EasyWeChat\Message\News;
  19. use EasyWeChat\Message\Text;
  20. use EasyWeChat\Message\Video;
  21. use EasyWeChat\Message\Voice;
  22. use EasyWeChat\Payment\Order;
  23. use EasyWeChat\Server\Guard;
  24. use think\Response;
  25. use crmeb\utils\Hook;
  26. class WechatService
  27. {
  28. private static $instance = null;
  29. public static function options()
  30. {
  31. $wechat = SystemConfigService::more([
  32. 'wechat_appid',
  33. 'wechat_appsecret',
  34. 'wechat_token',
  35. 'wechat_encodingaeskey',
  36. 'wechat_encode',
  37. ]);
  38. $payment = SystemConfigService::more([
  39. 'pay_weixin_appid',
  40. 'pay_weixin_appsecret',
  41. 'pay_weixin_mchid',
  42. 'pay_weixin_client_cert',
  43. 'pay_weixin_client_key',
  44. 'pay_weixin_key',
  45. 'pay_weixin_open',
  46. ]);
  47. $config = [
  48. 'app_id' => isset($wechat['wechat_appid']) ? trim($wechat['wechat_appid']) : '',
  49. 'secret' => isset($wechat['wechat_appsecret']) ? trim($wechat['wechat_appsecret']) : '',
  50. 'token' => isset($wechat['wechat_token']) ? trim($wechat['wechat_token']) : '',
  51. 'guzzle' => [
  52. 'timeout' => 10.0, // 超时时间(秒)
  53. 'verify' => false
  54. ],
  55. ];
  56. if (isset($wechat['wechat_encode']) &&
  57. (int)$wechat['wechat_encode'] > 0 &&
  58. isset($wechat['wechat_encodingaeskey']) &&
  59. !empty($wechat['wechat_encodingaeskey'])) {
  60. $config['aes_key'] = $wechat['wechat_encodingaeskey'];
  61. }
  62. if (isset($payment['pay_weixin_open']) && $payment['pay_weixin_open'] == 1) {
  63. $config['payment'] = [
  64. 'app_id' => trim($payment['pay_weixin_appid']),
  65. 'merchant_id' => trim($payment['pay_weixin_mchid']),
  66. 'key' => trim($payment['pay_weixin_key']),
  67. 'cert_path' => realpath('.' . $payment['pay_weixin_client_cert']),
  68. 'key_path' => realpath('.' . $payment['pay_weixin_client_key']),
  69. 'notify_url' => sys_config('site_url') . '/api/wechat/notify'
  70. ];
  71. }
  72. return $config;
  73. }
  74. public static function application($cache = false)
  75. {
  76. (self::$instance === null || $cache === true) && (self::$instance = new Application(self::options()));
  77. return self::$instance;
  78. }
  79. public static function serve(): Response
  80. {
  81. $wechat = self::application(true);
  82. $server = $wechat->server;
  83. self::hook($server);
  84. $response = $server->serve();
  85. return response($response->getContent());
  86. }
  87. /**
  88. * 监听行为
  89. * @param Guard $server
  90. */
  91. private static function hook($server)
  92. {
  93. $server->setMessageHandler(function ($message) {
  94. event('WechatMessageBefore', [$message]);
  95. switch ($message->MsgType) {
  96. case 'event':
  97. switch (strtolower($message->Event)) {
  98. case 'subscribe':
  99. $response = WechatReply::reply('subscribe');
  100. if (isset($message->EventKey)) {
  101. if ($message->EventKey && ($qrInfo = QrcodeService::getQrcode($message->Ticket, 'ticket'))) {
  102. QrcodeService::scanQrcode($message->Ticket, 'ticket');
  103. if (strtolower($qrInfo['third_type']) == 'spread') {
  104. try {
  105. $spreadUid = $qrInfo['third_id'];
  106. $uid = WechatUser::openidToUid($message->FromUserName, 'openid');
  107. if ($spreadUid == $uid) return '自己不能推荐自己';
  108. $userInfo = User::getUserInfo($uid);
  109. if ($userInfo['spread_uid']) return '已有推荐人!';
  110. if (!User::setSpreadUid($userInfo['uid'], $spreadUid)) {
  111. $response = '绑定推荐人失败!';
  112. }
  113. } catch (\Exception $e) {
  114. $response = $e->getMessage();
  115. }
  116. }
  117. }
  118. }
  119. break;
  120. case 'unsubscribe':
  121. event('WechatEventUnsubscribeBefore', [$message]);
  122. break;
  123. case 'scan':
  124. $response = WechatReply::reply('subscribe');
  125. if ($message->EventKey && ($qrInfo = QrcodeService::getQrcode($message->Ticket, 'ticket'))) {
  126. QrcodeService::scanQrcode($message->Ticket, 'ticket');
  127. if (strtolower($qrInfo['third_type']) == 'spread') {
  128. try {
  129. $spreadUid = $qrInfo['third_id'];
  130. $uid = WechatUser::openidToUid($message->FromUserName, 'openid');
  131. if ($spreadUid == $uid) return '自己不能推荐自己';
  132. $userInfo = User::getUserInfo($uid);
  133. if ($userInfo['spread_uid']) return '已有推荐人!';
  134. if (User::setSpreadUid($userInfo['uid'], $spreadUid)) {
  135. $response = '绑定推荐人失败!';
  136. }
  137. } catch (\Exception $e) {
  138. $response = $e->getMessage();
  139. }
  140. }
  141. }
  142. break;
  143. case 'location':
  144. $response = MessageRepositories::wechatEventLocation($message);
  145. break;
  146. case 'click':
  147. $response = WechatReply::reply($message->EventKey);
  148. break;
  149. case 'view':
  150. $response = MessageRepositories::wechatEventView($message);
  151. break;
  152. }
  153. break;
  154. case 'text':
  155. $response = WechatReply::reply($message->Content);
  156. break;
  157. case 'image':
  158. $response = MessageRepositories::wechatMessageImage($message);
  159. break;
  160. case 'voice':
  161. $response = MessageRepositories::wechatMessageVoice($message);
  162. break;
  163. case 'video':
  164. $response = MessageRepositories::wechatMessageVideo($message);
  165. break;
  166. case 'location':
  167. $response = MessageRepositories::wechatMessageLocation($message);
  168. break;
  169. case 'link':
  170. $response = MessageRepositories::wechatMessageLink($message);
  171. break;
  172. // ... 其它消息
  173. default:
  174. $response = MessageRepositories::wechatMessageOther($message);
  175. break;
  176. }
  177. return $response ?? false;
  178. });
  179. }
  180. /**
  181. * 多客服消息转发
  182. * @param string $account
  183. * @return \EasyWeChat\Message\Transfer
  184. */
  185. public static function transfer($account = '')
  186. {
  187. $transfer = new \EasyWeChat\Message\Transfer();
  188. return empty($account) ? $transfer : $transfer->to($account);
  189. }
  190. /**
  191. * 上传永久素材接口
  192. * @return \EasyWeChat\Material\Material
  193. */
  194. public static function materialService()
  195. {
  196. return self::application()->material;
  197. }
  198. /**
  199. * 上传临时素材接口
  200. * @return \EasyWeChat\Material\Temporary
  201. */
  202. public static function materialTemporaryService()
  203. {
  204. return self::application()->material_temporary;
  205. }
  206. /**
  207. * 用户接口
  208. * @return \EasyWeChat\User\User
  209. */
  210. public static function userService()
  211. {
  212. return self::application()->user;
  213. }
  214. /**
  215. * 客服消息接口
  216. * @param null $to
  217. * @param null $message
  218. */
  219. public static function staffService()
  220. {
  221. return self::application()->staff;
  222. }
  223. /**
  224. * 微信公众号菜单接口
  225. * @return \EasyWeChat\Menu\Menu
  226. */
  227. public static function menuService()
  228. {
  229. return self::application()->menu;
  230. }
  231. /**
  232. * 微信二维码生成接口
  233. * @return \EasyWeChat\QRCode\QRCode
  234. */
  235. public static function qrcodeService()
  236. {
  237. return self::application()->qrcode;
  238. }
  239. /**
  240. * 微信永久二维码生成接口 小于10万个
  241. * @return \EasyWeChat\QRCode\QRCode
  242. */
  243. public static function qrcodeForeverService($sceneValue)
  244. {
  245. return self::application()->qrcode->forever($sceneValue);
  246. }
  247. /**
  248. * 微信临时二维码生成接口 30天有效期
  249. * @return \EasyWeChat\QRCode\QRCode
  250. */
  251. public static function qrcodeTempService($sceneValue, $expireSeconds = 2592000)
  252. {
  253. return self::application()->qrcode->temporary($sceneValue, $expireSeconds);
  254. }
  255. /**
  256. * 短链接生成接口
  257. * @return \EasyWeChat\Url\Url
  258. */
  259. public static function urlService()
  260. {
  261. return self::application()->url;
  262. }
  263. /**
  264. * 用户授权
  265. * @return \Overtrue\Socialite\Providers\WeChatProvider
  266. */
  267. public static function oauthService()
  268. {
  269. return self::application()->oauth;
  270. }
  271. /**
  272. * 模板消息接口
  273. * @return \EasyWeChat\Notice\Notice
  274. */
  275. public static function noticeService()
  276. {
  277. return self::application()->notice;
  278. }
  279. public static function sendTemplate($openid, $templateId, array $data, $url = null, $defaultColor = null)
  280. {
  281. $notice = self::noticeService()->to($openid)->template($templateId)->andData($data);
  282. if ($url !== null) $notice->url($url);
  283. if ($defaultColor !== null) $notice->defaultColor($defaultColor);
  284. return $notice->send();
  285. }
  286. /**
  287. * 支付
  288. * @return \EasyWeChat\Payment\Payment
  289. */
  290. public static function paymentService()
  291. {
  292. return self::application()->payment;
  293. }
  294. public static function downloadBill($day, $type = 'ALL')
  295. {
  296. // $payment = self::paymentService();
  297. // $merchant = $payment->getMerchant();
  298. // $params = [
  299. // 'appid' => $merchant->app_id,
  300. // 'bill_date'=>$day,
  301. // 'bill_type'=>strtoupper($type),
  302. // 'mch_id'=> $merchant->merchant_id,
  303. // 'nonce_str' => uniqid()
  304. // ];
  305. // $params['sign'] = \EasyWeChat\Payment\generate_sign($params, $merchant->key, 'md5');
  306. // $xml = XML::build($params);
  307. // dump(self::paymentService()->downloadBill($day)->getContents());
  308. // dump($payment->getHttp()->request('https://api.mch.weixin.qq.com/pay/downloadbill','POST',[
  309. // 'body' => $xml,
  310. // 'stream'=>true
  311. // ])->getBody()->getContents());
  312. }
  313. public static function userTagService()
  314. {
  315. return self::application()->user_tag;
  316. }
  317. public static function userGroupService()
  318. {
  319. return self::application()->user_group;
  320. }
  321. /**
  322. * 生成支付订单对象
  323. * @param $openid
  324. * @param $out_trade_no
  325. * @param $total_fee
  326. * @param $attach
  327. * @param $body
  328. * @param string $detail
  329. * @param string $trade_type
  330. * @param array $options
  331. * @return Order
  332. */
  333. protected static function paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [])
  334. {
  335. $total_fee = bcmul($total_fee, 100, 0);
  336. $order = array_merge(compact('out_trade_no', 'total_fee', 'attach', 'body', 'detail', 'trade_type'), $options);
  337. if (!is_null($openid)) $order['openid'] = $openid;
  338. if ($order['detail'] == '') unset($order['detail']);
  339. return new Order($order);
  340. }
  341. /**
  342. * 获得下单ID
  343. * @param $openid
  344. * @param $out_trade_no
  345. * @param $total_fee
  346. * @param $attach
  347. * @param $body
  348. * @param string $detail
  349. * @param string $trade_type
  350. * @param array $options
  351. * @return mixed
  352. */
  353. public static function paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [])
  354. {
  355. $order = self::paymentOrder($openid, $out_trade_no, $total_fee, $attach, $body, $detail, $trade_type, $options);
  356. $result = self::paymentService()->prepare($order);
  357. if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
  358. try {
  359. PaymentRepositories::wechatPaymentPrepare($order, $result->prepay_id);
  360. } catch (\Exception $e) {
  361. }
  362. return $result;
  363. } else {
  364. if ($result->return_code == 'FAIL') {
  365. exception('微信支付错误返回:' . $result->return_msg);
  366. } else if (isset($result->err_code)) {
  367. exception('微信支付错误返回:' . $result->err_code_des);
  368. } else {
  369. exception('没有获取微信支付的预支付ID,请重新发起支付!');
  370. }
  371. exit;
  372. }
  373. }
  374. /**
  375. * 获得jsSdk支付参数
  376. * @param $openid
  377. * @param $out_trade_no
  378. * @param $total_fee
  379. * @param $attach
  380. * @param $body
  381. * @param string $detail
  382. * @param string $trade_type
  383. * @param array $options
  384. * @return array|string
  385. */
  386. public static function jsPay($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'JSAPI', $options = [])
  387. {
  388. $paymentPrepare = self::paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail, $trade_type, $options);
  389. return self::paymentService()->configForJSSDKPayment($paymentPrepare->prepay_id);
  390. }
  391. /**
  392. * 获得AppSdk支付参数
  393. * @param $openid
  394. * @param $out_trade_no
  395. * @param $total_fee
  396. * @param $attach
  397. * @param $body
  398. * @param string $detail
  399. * @param string $trade_type
  400. * @param array $options
  401. * @return array|string
  402. */
  403. public static function appPay($openid, $out_trade_no, $total_fee, $attach, $body, $detail = '', $trade_type = 'APP', $options = [])
  404. {
  405. $paymentPrepare = self::paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail, $trade_type, $options);
  406. return self::paymentService()->configForAppPayment($paymentPrepare->prepay_id);
  407. }
  408. /**
  409. * 使用商户订单号退款
  410. * @param $orderNo
  411. * @param $refundNo
  412. * @param $totalFee
  413. * @param null $refundFee
  414. * @param null $opUserId
  415. * @param string $refundReason
  416. * @param string $type
  417. * @param string $refundAccount
  418. */
  419. public static function refund($orderNo, $refundNo, $totalFee, $refundFee = null, $opUserId = null, $refundReason = '', $type = 'out_trade_no', $refundAccount = 'REFUND_SOURCE_UNSETTLED_FUNDS')
  420. {
  421. $totalFee = floatval($totalFee);
  422. $refundFee = floatval($refundFee);
  423. return self::paymentService()->refund($orderNo, $refundNo, $totalFee, $refundFee, $opUserId, $type, $refundAccount, $refundReason);
  424. }
  425. public static function payOrderRefund($orderNo, array $opt)
  426. {
  427. if (!isset($opt['pay_price'])) exception('缺少pay_price');
  428. $totalFee = floatval(bcmul($opt['pay_price'], 100, 0));
  429. $refundFee = isset($opt['refund_price']) ? floatval(bcmul($opt['refund_price'], 100, 0)) : null;
  430. $refundReason = isset($opt['desc']) ? $opt['desc'] : '';
  431. $refundNo = isset($opt['refund_id']) ? $opt['refund_id'] : $orderNo;
  432. $opUserId = isset($opt['op_user_id']) ? $opt['op_user_id'] : null;
  433. $type = isset($opt['type']) ? $opt['type'] : 'out_trade_no';
  434. /*仅针对老资金流商户使用
  435. REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款)
  436. REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款*/
  437. $refundAccount = isset($opt['refund_account']) ? $opt['refund_account'] : 'REFUND_SOURCE_UNSETTLED_FUNDS';
  438. try {
  439. $res = (self::refund($orderNo, $refundNo, $totalFee, $refundFee, $opUserId, $refundReason, $type, $refundAccount));
  440. if ($res->return_code == 'FAIL') exception('退款失败:' . $res->return_msg);
  441. if (isset($res->err_code)) exception('退款失败:' . $res->err_code_des);
  442. } catch (\Exception $e) {
  443. exception($e->getMessage());
  444. }
  445. return true;
  446. }
  447. /**
  448. * 微信支付成功回调接口
  449. */
  450. public static function handleNotify()
  451. {
  452. self::paymentService()->handleNotify(function ($notify, $successful) {
  453. if ($successful && isset($notify->out_trade_no)) {
  454. if (isset($notify->attach) && $notify->attach) {
  455. if (($count = strpos($notify->out_trade_no, '_')) !== false) {
  456. $notify->out_trade_no = substr($notify->out_trade_no, $count + 1);
  457. }
  458. return (new Hook(PaymentRepositories::class, 'wechat'))->listen($notify->attach, $notify->out_trade_no);
  459. }
  460. WechatMessage::setOnceMessage($notify, $notify->openid, 'payment_success', $notify->out_trade_no);
  461. return false;
  462. }
  463. });
  464. }
  465. /**
  466. * jsSdk
  467. * @return \EasyWeChat\Js\Js
  468. */
  469. public static function jsService()
  470. {
  471. return self::application()->js;
  472. }
  473. public static function jsSdk($url = '')
  474. {
  475. $apiList = ['editAddress', 'openAddress', 'updateTimelineShareData', 'updateAppMessageShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'];
  476. $jsService = self::jsService();
  477. if ($url) $jsService->setUrl($url);
  478. try {
  479. return $jsService->config($apiList);
  480. } catch (\Exception $e) {
  481. return '{}';
  482. }
  483. }
  484. /**
  485. * 回复文本消息
  486. * @param string $content 文本内容
  487. * @return Text
  488. */
  489. public static function textMessage($content)
  490. {
  491. return new Text(compact('content'));
  492. }
  493. /**
  494. * 回复图片消息
  495. * @param string $media_id 媒体资源 ID
  496. * @return Image
  497. */
  498. public static function imageMessage($media_id)
  499. {
  500. return new Image(compact('media_id'));
  501. }
  502. /**
  503. * 回复视频消息
  504. * @param string $media_id 媒体资源 ID
  505. * @param string $title 标题
  506. * @param string $description 描述
  507. * @param null $thumb_media_id 封面资源 ID
  508. * @return Video
  509. */
  510. public static function videoMessage($media_id, $title = '', $description = '...', $thumb_media_id = null)
  511. {
  512. return new Video(compact('media_id', 'title', 'description', 'thumb_media_id'));
  513. }
  514. /**
  515. * 回复声音消息
  516. * @param string $media_id 媒体资源 ID
  517. * @return Voice
  518. */
  519. public static function voiceMessage($media_id)
  520. {
  521. return new Voice(compact('media_id'));
  522. }
  523. /**
  524. * 回复图文消息
  525. * @param string|array $title 标题
  526. * @param string $description 描述
  527. * @param string $url URL
  528. * @param string $image 图片链接
  529. */
  530. public static function newsMessage($title, $description = '...', $url = '', $image = '')
  531. {
  532. if (is_array($title)) {
  533. if (isset($title[0]) && is_array($title[0])) {
  534. $newsList = [];
  535. foreach ($title as $news) {
  536. $newsList[] = self::newsMessage($news);
  537. }
  538. return $newsList;
  539. } else {
  540. $data = $title;
  541. }
  542. } else {
  543. $data = compact('title', 'description', 'url', 'image');
  544. }
  545. return new News($data);
  546. }
  547. /**
  548. * 回复文章消息
  549. * @param string|array $title 标题
  550. * @param string $thumb_media_id 图文消息的封面图片素材id(必须是永久 media_ID)
  551. * @param string $source_url 图文消息的原文地址,即点击“阅读原文”后的URL
  552. * @param string $content 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS
  553. * @param string $author 作者
  554. * @param string $digest 图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空
  555. * @param int $show_cover_pic 是否显示封面,0为false,即不显示,1为true,即显示
  556. * @param int $need_open_comment 是否打开评论,0不打开,1打开
  557. * @param int $only_fans_can_comment 是否粉丝才可评论,0所有人可评论,1粉丝才可评论
  558. * @return Article
  559. */
  560. public static function articleMessage($title, $thumb_media_id, $source_url, $content = '', $author = '', $digest = '', $show_cover_pic = 0, $need_open_comment = 0, $only_fans_can_comment = 1)
  561. {
  562. $data = is_array($title) ? $title : compact('title', 'thumb_media_id', 'source_url', 'content', 'author', 'digest', 'show_cover_pic', 'need_open_comment', 'only_fans_can_comment');
  563. return new Article($data);
  564. }
  565. /**
  566. * 回复素材消息
  567. * @param string $type [mpnews、 mpvideo、voice、image]
  568. * @param string $media_id 素材 ID
  569. * @return Material
  570. */
  571. public static function materialMessage($type, $media_id)
  572. {
  573. return new Material($type, $media_id);
  574. }
  575. /**
  576. * 作为客服消息发送
  577. * @param $to
  578. * @param $message
  579. * @return bool
  580. */
  581. public static function staffTo($to, $message)
  582. {
  583. $staff = self::staffService();
  584. $staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
  585. $res = $staff->to($to)->send();
  586. return $res;
  587. }
  588. /**
  589. * 获得用户信息
  590. * @param array|string $openid
  591. * @return \EasyWeChat\Support\Collection
  592. */
  593. public static function getUserInfo($openid)
  594. {
  595. $userService = self::userService();
  596. $userInfo = is_array($openid) ? $userService->batchGet($openid) : $userService->get($openid);
  597. return $userInfo;
  598. }
  599. }