|
|
@@ -1,4 +1,6 @@
|
|
|
-<?php namespace App\Servers\Wechat;
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Servers\Wechat;
|
|
|
|
|
|
use EasyWeChat\Factory;
|
|
|
|
|
|
@@ -12,7 +14,8 @@ class Official
|
|
|
protected \EasyWeChat\OfficialAccount\Application $app;
|
|
|
|
|
|
// 构造函数
|
|
|
- public function __construct(){
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
// 应用实例
|
|
|
$this->app = $this->getApp();
|
|
|
}
|
|
|
@@ -23,9 +26,10 @@ class Official
|
|
|
* @return \EasyWeChat\OfficialAccount\Application
|
|
|
*
|
|
|
*/
|
|
|
- public function getApp(){
|
|
|
+ public function getApp()
|
|
|
+ {
|
|
|
// 获取配置
|
|
|
- $this->app = Factory::officialAccount(config('wechat.official',[]));
|
|
|
+ $this->app = Factory::officialAccount(config('wechat.official', []));
|
|
|
// 返回结果
|
|
|
return $this->app;
|
|
|
}
|
|
|
@@ -36,11 +40,12 @@ class Official
|
|
|
*
|
|
|
*
|
|
|
*/
|
|
|
- public function userFromCode($code){
|
|
|
+ public function userFromCode($code)
|
|
|
+ {
|
|
|
// 获取手机号
|
|
|
- $result = $this->app->oauth->userFromCode($code);
|
|
|
+ $result = $this->app->oauth->userFromCode($code);
|
|
|
// 判断结果
|
|
|
- if( !empty($result['errcode']) ) return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
|
|
|
+ if (!empty($result['errcode'])) return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
|
|
|
// 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
|
|
|
return $result;
|
|
|
}
|
|
|
@@ -49,11 +54,12 @@ class Official
|
|
|
* 获取JSSDK的配置数组
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getJssdkConfig($url=''){
|
|
|
+ public function getJssdkConfig($url = '')
|
|
|
+ {
|
|
|
// 如果指定路径的话
|
|
|
- if( $url ) $this->app->jssdk->setUrl($url);
|
|
|
+ if ($url) $this->app->jssdk->setUrl($url);
|
|
|
// 获取JSSDK的配置对象
|
|
|
- $config = $this->app->jssdk->buildConfig(['updateAppMessageShareData','updateTimelineShareData'],false,false,false);
|
|
|
+ $config = $this->app->jssdk->buildConfig(['updateAppMessageShareData', 'updateTimelineShareData'], false, false, false);
|
|
|
// 获取JSSDK的配置数组
|
|
|
return $config;
|
|
|
}
|
|
|
@@ -62,17 +68,18 @@ class Official
|
|
|
* @param array $params
|
|
|
*
|
|
|
*/
|
|
|
- public function sendSubscription($params){
|
|
|
- // 获取手机号
|
|
|
- $result = $this->app->template_message->sendSubscription([
|
|
|
+ public function sendSubscription($params)
|
|
|
+ {
|
|
|
+
|
|
|
+ $result = $this->app->template_message->sendSubscription([
|
|
|
'touser' => $params['openid'],
|
|
|
'template_id' => 'template-id',
|
|
|
- 'url' => $params['url'],
|
|
|
+ 'miniprogram' => $params['miniprogram'],
|
|
|
'scene' => 1000,
|
|
|
'data' => $params['data'],
|
|
|
]);
|
|
|
// 判断结果
|
|
|
- if( !empty($result['errcode']) ) return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
|
|
|
+ if (!empty($result['errcode'])) return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
|
|
|
// 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
|
|
|
return $result;
|
|
|
}
|
|
|
@@ -81,9 +88,10 @@ class Official
|
|
|
* @param array $params
|
|
|
*
|
|
|
*/
|
|
|
- public function send($params){
|
|
|
+ public function send($params)
|
|
|
+ {
|
|
|
// 获取手机号
|
|
|
- $result = $this->app->template_message->send([
|
|
|
+ $result = $this->app->template_message->send([
|
|
|
'touser' => $params['openid'],
|
|
|
'template_id' => 'template-id',
|
|
|
'url' => $params['url'],
|
|
|
@@ -91,7 +99,7 @@ class Official
|
|
|
'data' => $params['data'],
|
|
|
]);
|
|
|
// 判断结果
|
|
|
- if( !empty($result['errcode']) ) return ['error'=>$result['errcode'].'=>'.$result['errmsg']];
|
|
|
+ if (!empty($result['errcode'])) return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
|
|
|
// 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
|
|
|
return $result;
|
|
|
}
|