imaxwen / yii2-easy-wechat Goto Github PK
View Code? Open in Web Editor NEWWeChat SDK for yii2 , based on overtrue/wechat.
License: MIT License
WeChat SDK for yii2 , based on overtrue/wechat.
License: MIT License
开放平台怎样配置信息?
现在如果改成是redis
做缓存,则必须使用包里面的RedisCache
而日志只能写到指定的文件上,根本用不到log
组件
如题
在session保存的时候有这个属性 但是类里没有 报错了
目前的overtrue/wechat
默认的scope为 snsapi_login
, 但是如果需要使用其他的scope, 例如snsapi_base
却无法设置
1.独立安装easywechat,正常运行,用微信发送信息,公众号能正常自动回复消息。说明我服务器环境没问题。
2.先安装了基础版本yii2,composer用的是国外源
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
cd basic
composer require maxwen/yii2-easy-wechat
经过配置,以下代码,服务器能正确验证,但是公众号不能正常回复消息,
显示“该公众号暂时无法提供服务“
$app = Yii::$app->wechat; $server = $app->server; $server->setMessageHandler(function ($message) { return "您好!欢迎关注我!"; }); $response = $server->serve(); $response->send();
微信上发送信息给公众号,微信不能正常回复消息,log无debug信息。
log在验证服务器配置的时候是有debug信息的,如下:
[2017-06-08 22:50:16] easywechat.DEBUG: Current config: {"debug":true,"app_id":"***bd809","secret":"8610b","token":"qyzg111","aes_key":"23s1aIgUiYJKcts3zAf1yCFkQvULV49zKFMpGirhljq","log":{"level":"debug","permission":511,"file":"/home/wwwroot/wx..com/log.txt"}} []
[2017-06-08 22:50:16] easywechat.DEBUG: Request received: {"Method":"GET","URI":"/site/weixin?signature=fec0b467a15bf7ea7075d10a8e413a242cb375b4&echostr=1389749417337909086×tamp=1496933464&nonce=3075139355","Query":"echostr=1389749417337909086&nonce=3075139355&signature=fec0b467a15bf7ea7075d10a8e413a242cb375b4×tamp=1496933464","Protocal":"HTTP/1.0","Content":""} []
[2017-06-08 22:50:16] easywechat.DEBUG: Output 'echostr' is '1389749417337909086'. [] []
大概哪里出了问题呢??
说找不到WechatOrder.
是不是要自己写这个类呀?
比如说我想用jssdk ,我应该怎么调用呢?
是用 $jssdk = Yii::$app->wechat->js 呢,还是 $jssdk = Yii::$app->wecaht->app->js,还有一些其他的,本地调试很费劲。多谢!!!
正常运转代码:
public function actionWeixin(){
$app = Yii::$app->wechat;
$server = $app->server;
$server->setMessageHandler(function ($message) {
return "您好!欢迎关注我!";
});
return $server->serve()->send();
}
如下代码出错,按着https://github.com/overtrue/wechat 的usage示例代码来的
public function actionWeixin(){
$app = Yii::$app->wechat;
$user = $app->user;
$server = $app->server;
$server->setMessageHandler(function ($message) use ($user) {
$fromUser = $user->get($message->FromUserName);
//日志信息显示没有get这个方法
//也补上了 use EasyWeChat\Foundation\Application;
return "{$fromUser->nickname} ,您好!欢迎关注我!";
});
return $server->serve()->send();
}
Overtrue\Socialite\AuthorizeFailedException
Authorize Failed: {"errcode":40029,"errmsg":"invalid code, hints: [ req_id: I4Fr8a0006th38 ]"}
支持一下 👍
作为一名菜鸟我的问题很多....
如何快速开始呢?求一个简单示例,
类似
https://easywechat.org/zh-cn/docs/tutorial.html
貌似Yii::$app->params['WECHAT']只能设置一个吧,那如果有两个号,怎么操作呢?
new Application(Yii::$app->params['WECHAT']);
正常显示了认证页面,然后返回我的业务页面就出错了
业务页写了2个版本,1页面按着你的示例代码来,2页面按着easywechat的示例代码来的,均出错,
代码如下
`
'oauth' => [//配置代码
'scopes' => ['snsapi_userinfo'],
'callback' => 'site/callback',
],`
`
public function actionCallback()//认证回调页面
{
$app = Yii::$app->wechat;
$oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
$user = $oauth->user();
$_SESSION['wechat_user'] = $user->toArray();
$targetUrl = empty($_SESSION['target_url']) ? '/' : $_SESSION['target_url'];
header('location:'. $targetUrl); // 跳转到 user/profile
}
`
public function actionMyapp1()//业务页面1
{
if(Yii::$app->wechat->isWechat && !Yii::$app->wechat->isAuthorized()) {
return Yii::$app->wechat->authorizeRequired()->send();
}
echo '111';
}
public function actionMyapp2()//业务页面2
{
$this->layout = false;
$app = Yii::$app->wechat;
$oauth = $app->oauth;
// 未登录
if (empty($_SESSION['wechat_user'])) {
$_SESSION['target_url'] = 'site/myapp';
return $oauth->redirect();
// 这里不一定是return,如果你的框架action不是返回内容的话你就得使用
// $oauth->redirect()->send();
}
// 已经登录过
$user = $_SESSION['wechat_user'];
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.