dyjh 6 роки тому
батько
коміт
1d9d2c0444

+ 4 - 2
app/Http/Controllers/Admin/Base/IndexController.php

xqd
@@ -80,9 +80,11 @@ class IndexController extends Controller
                 'num' => $count_all,
             ];
             $name = $val['realname'];
-            $geoCoordMap->$name = 111;
+            if (empty($name) || empty($val['lon']) || $val['lat']) {
+                continue;
+            }
+            $geoCoordMap->$name = [$val['lon'], $val['lat']];
         }
-        dd($geoCoordMap);
         $data = json_encode($data);
         $geoCoordMap = json_encode($geoCoordMap);
         $day = substr($day, 0, strlen($day) - 1) . ']';

+ 1 - 1
app/Http/Controllers/Api/V1/AlbumController.php

xqd
@@ -1903,7 +1903,7 @@ class AlbumController extends Controller
             'store_id' => 'required',
         ],[
             'address.required'=>'缺少地址参数',
-            'real_name.required'=>'缺少信息参数',
+            'realname.required'=>'缺少信息参数',
             'phone.required'=>'缺少电话参数',
             'store_id.required'=>'缺少商户参数',
         ]);

+ 104 - 12
app/Http/Controllers/Web/AuthController.php

xqd xqd
@@ -49,7 +49,6 @@ class AuthController extends Controller
         ];
         $app = Factory::officialAccount($config);
         $oauth = $app->oauth;
-// 获取 OAuth 授权结果用户信息
         $user = $oauth->user()->toArray();
         $check_user = AlbumUserModel::where([['store_id',$store_id],['wechat_union_id',$user['original']['unionid']]])->first();
         if ($check_user) {
@@ -72,18 +71,111 @@ class AuthController extends Controller
 
     public function notifyAccount(Request $request)
     {
-        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
-        if (!empty($postStr)) {
-            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
-            $fromUsername = $postObj->FromUserName;
-            $toUsername = $postObj->ToUserName;
-            $MsgT = $postObj->MsgType;
-            $time = time();
-            \Log::info($postObj);
-            //如果用户发的text类型
+        $store_id = $request->input('store_id');
+        $config = [
+            'app_id' => 'wxbce144ca3da7aa23',
+            'secret' => '4d97eba675deeea187e1ebc32c1399da',
+            'response_type' => 'array',
+        ];
+
+        $app = Factory::officialAccount($config);
+        if (isset($_GET["echostr"])) {
+            $echoStr = $_GET["echostr"];
+            //对接规则
+            $signature = $_GET["signature"];
+            $timestamp = $_GET["timestamp"];
+            $nonce = $_GET["nonce"];
+            $token = 'bshbdajdbjadwedwqer';
+            $tmpArr = array($token, $timestamp, $nonce);
+            sort($tmpArr, SORT_STRING);
+            $tmpStr = implode($tmpArr);
+            $tmpStr = sha1($tmpStr);
+            if ($tmpStr == $signature) {
+                echo $echoStr;
+            } else {
+                echo "";
+                exit;
+            }
         } else {
-            echo "";
-            exit;
+            $postStr = file_get_contents("php://input");
+            if (!empty($postStr)) {
+                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
+                $fromUsername = $postObj->FromUserName;
+                $toUsername = $postObj->ToUserName;
+                $MsgT = $postObj->MsgType;
+                $time = time();
+                //如果用户发的text类型
+                if ($MsgT == "text") {
+                    $key = trim($postObj->Content);
+                    $fromUsername = $postObj->FromUserName;
+                    $textTpl = "<xml>
+                            <ToUserName><![CDATA[%s]]></ToUserName>
+                            <FromUserName><![CDATA[%s]]></FromUserName>
+                            <CreateTime>%s</CreateTime>
+                            <MsgType><![CDATA[%s]]></MsgType>
+                            <Content><![CDATA[%s]]></Content>
+                            </xml>";
+                    $msgType = "text";
+                    if ($key == '绑定') {
+                        $user = $app->user->get($fromUsername);
+                        $check_user = AlbumUserModel::where([['store_id',$store_id],['wechat_union_id',$user['unionid']]])->first();
+                        if ($check_user) {
+                            $check_user->g_open_id = $user['id'];
+                            $res = $check_user->save();
+                        } else {
+                            $data['username'] = $user['nickname'];
+                            $data['wechat_union_id'] = $user['unionid'];
+                            $data['avatar'] = $user['headimgurl'];
+                            $data['g_open_id'] = $fromUsername;
+                            $data['store_id'] = $store_id;
+                            $data['is_dealer'] = 0;
+                            $data['role'] = 0;
+                            $data['model'] = 0;
+                            $data['up_agent_id'] = 0;
+                            $res = AlbumUserModel::create($data);
+                        }
+                        if ($res) {
+                            $contentStr = "绑定成功";
+                        } else {
+                            $contentStr = "绑定失败";
+                        }
+                    } else {
+                        $contentStr = "回复 绑定 即可绑定用户";
+                    }
+
+                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
+                    echo $resultStr;
+                    exit;
+                }
+
+                //如果用户发的event(事件)类型
+                if ($MsgT == "event") {
+                    $Event = $postObj->Event;
+                    if ($Event == 'subscribe') {
+                        $contentStr = "欢迎关注,回复 绑定 即可绑定用户";
+                    } else {
+                        $contentStr = "希望您下次关注,但您收不到此条消息了";
+                    }
+
+                    $textTpl = "<xml>
+                            <ToUserName><![CDATA[%s]]></ToUserName>
+                            <FromUserName><![CDATA[%s]]></FromUserName>
+                            <CreateTime>%s</CreateTime>
+                            <MsgType><![CDATA[%s]]></MsgType>
+                            <Content><![CDATA[%s]]></Content>
+                            </xml>";
+                    $Title = $postObj->Title;
+                    $Description = $postObj->Description;
+                    $Url = $postObj->Url;
+                    $msgType = 'text';
+                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
+                    echo $resultStr;
+                    exit;
+                }
+            } else {
+                echo "";
+                exit;
+            }
         }
     }
 

+ 1 - 0
app/Http/Middleware/VerifyCsrfToken.php

xqd
@@ -17,6 +17,7 @@ class VerifyCsrfToken extends BaseVerifier
         "wechat",
         "notify",
         "admin/Base/Attachment/*",
+        '/web/notify-account'
     ];
 
     public function handle($request, Closure $next)

+ 23 - 1
routes/web.php

xqd xqd
@@ -23,6 +23,7 @@ Route::get('image/{md5}', [
 ]);
 
 
+<<<<<<< HEAD
 ///dd(request()->input('route'));
 //后台
 if (strpos(request()->getRequestUri(), '/addons/') !== false) {
@@ -60,4 +61,25 @@ if (strpos(request()->getRequestUri(), '/addons/') !== false) {
         }
     }
 
-}
+}
+=======
+
+// Route::get('/test',function() {
+
+//     $password = bcrypt('admin');
+//     dd($password);
+//     dd(dict()->get('user_info','work_type'));
+//     $password = bcrypt('admin');
+//     dd($password);
+//     $obj = new \App\Services\User\Info();
+//     $obj = $obj->find(1);
+//     var_dump($obj);exit;
+// });
+
+Route::get('/test', 'TestController@index');
+Route::get('/web/bind', 'Web\AuthController@bind');
+Route::any('/web/notify', 'Web\AuthController@notify');
+Route::any('/web/notify-account', 'Web\AuthController@notifyAccount');
+/*Route::group(['prefix'=>'web','namespace'=>'Web','middleware' => ['web', 'wechat.oauth:snsapi_userinfo']],function (){
+    Route::any('bind','AuthController@bind');});*/
+>>>>>>> master