-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
145 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
/** | ||
* PhpStorm Meta file, to provide autocomplete information for PhpStorm | ||
* Generated on 2020-10-15 21:05:19. | ||
* Generated on 2020-10-16 15:31:50. | ||
* | ||
* @author Barry vd. Heuvel <[email protected]> | ||
* @see https://github.com/barryvdh/laravel-ide-helper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Wechat; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Hdliyu\Wechat\Message; | ||
use Hdliyu\Wechat\Wechat; | ||
use Illuminate\Http\Request; | ||
use Log; | ||
|
||
class SubscribeController extends Controller | ||
{ | ||
public function handle(Request $request,Wechat $wechat,Message $message) | ||
{ | ||
if($message->isSubscribe()){ | ||
return $message->text('感谢关注'); | ||
} | ||
// return $message->text('你好'); | ||
/* return $message->news([ | ||
['title'=>'n你好1','description'=>'xxx','picurl'=>'http://front.wxnet.vip/xite/images/top/20170617104248203.png','url'=>'https://www.baidu.com'], | ||
]);*/ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ class VerifyCsrfToken extends Middleware | |
* @var array | ||
*/ | ||
protected $except = [ | ||
// | ||
'wechat/*' | ||
'wechat' | ||
]; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
return [ | ||
'wechat'=>[ | ||
'token'=>'hdliyu666' | ||
'token'=>'hdliyu666', | ||
'appID'=>'wxb6de5a7b5c78ba5d', | ||
'appsecret'=>'4c0a4d74be90e8051c197a26a2dd84ed' | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Hdliyu\Wechat; | ||
|
||
use Hdliyu\Wechat\Message\MsgType; | ||
use Hdliyu\Wechat\Message\Send; | ||
|
||
class Message extends Wechat { | ||
use Send,MsgType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace Hdliyu\Wechat\Message; | ||
|
||
trait MsgType{ | ||
|
||
public function isText() | ||
{ | ||
return $this->MsgType == 'text'; | ||
} | ||
|
||
public function isImage() | ||
{ | ||
return $this->MsgType == 'image'; | ||
} | ||
|
||
public function isVoice() | ||
{ | ||
return $this->MsgType == 'voice'; | ||
} | ||
|
||
public function isVideo() | ||
{ | ||
return $this->MsgType == 'video'; | ||
} | ||
|
||
public function isMusic() | ||
{ | ||
return $this->MsgType == 'music'; | ||
} | ||
|
||
public function isSubscribe() | ||
{ | ||
return $this->MsgType == 'event' && $this->Event == 'subscribe'; | ||
} | ||
|
||
public function isUnsubscribe() | ||
{ | ||
return $this->MsgType == 'event' && $this->Event == 'unsubscribe'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace Hdliyu\Wechat\Message; | ||
|
||
|
||
trait Send{ | ||
|
||
public function text($content) | ||
{ | ||
$xml=<<<php | ||
<xml> | ||
<ToUserName><![CDATA[%s]]></ToUserName> | ||
<FromUserName><![CDATA[%s]]></FromUserName> | ||
<CreateTime>%s</CreateTime> | ||
<MsgType><![CDATA[text]]></MsgType> | ||
<Content><![CDATA[%s]]></Content> | ||
</xml> | ||
php; | ||
return sprintf($xml,$this->FromUserName,$this->ToUserName,time(),$content); | ||
} | ||
|
||
public function news(array $data) | ||
{ | ||
$xml=<<<xml | ||
<xml> | ||
<ToUserName><![CDATA[%s]]></ToUserName> | ||
<FromUserName><![CDATA[%s]]></FromUserName> | ||
<CreateTime>%s</CreateTime> | ||
<MsgType><![CDATA[news]]></MsgType> | ||
<ArticleCount>%s</ArticleCount> | ||
<Articles> | ||
%s | ||
</Articles> | ||
</xml> | ||
xml; | ||
$news = ''; | ||
$articleXml = <<<php | ||
<item> | ||
<Title><![CDATA[%s]]></Title> | ||
<Description><![CDATA[%s]]></Description> | ||
<PicUrl><![CDATA[%s]]></PicUrl> | ||
<Url><![CDATA[%s]]></Url> | ||
</item> | ||
php; | ||
foreach ($data as $article){ | ||
$news.=sprintf($articleXml,$article['title'],$article['description'],$article['picurl'],$article['url']); | ||
} | ||
return sprintf($xml,$this->FromUserName,$this->ToUserName,time(),count($data),$news); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
<?php | ||
namespace Hdliyu\Wechat; | ||
|
||
use Log; | ||
|
||
class Wechat{ | ||
public $message; | ||
protected $message; | ||
|
||
public function __construct() | ||
{ | ||
$this->bind(); | ||
$this->message = $this->getMessage(); | ||
\Log::info($this->message); | ||
$this->getMessage(); | ||
} | ||
|
||
protected function getMessage() | ||
public function getMessage() | ||
{ | ||
$message = (array)simplexml_load_string(file_get_contents('php://input')); | ||
return $message; | ||
$content = file_get_contents('php://input'); | ||
if($content){ | ||
return $this->message = simplexml_load_string($content); | ||
} | ||
} | ||
|
||
public function __get($name) | ||
{ | ||
return $this->message->$name??null; | ||
} | ||
|
||
protected function bind() | ||
{ | ||
if(isset($_GET['ignature'],$_GET['timestamp'],$_GET['nonce'],$_GET['echostr'])){ | ||
$signature = $_GET['ignature']; | ||
if(isset($_GET['signature'],$_GET['timestamp'],$_GET['nonce'],$_GET['echostr'])){ | ||
$signature = $_GET['signature']; | ||
$timestamp = $_GET['timestamp']; | ||
$nonce = $_GET['nonce']; | ||
$token = config('hdliyu.wechat.token'); | ||
$tmpArr = [$token, $timestamp, $nonce]; | ||
sort($tmpArr, SORT_STRING); | ||
if( sha1(implode( $tmpArr )) == $signature ){ | ||
die($_GET['echostr']); | ||
}else{ | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
} | ||
|
||
} |