| 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) {
|
| xqd
@@ -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;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|