overtrue / laravel-wechat Goto Github PK
View Code? Open in Web Editor NEW微信 SDK for Laravel, 基于 overtrue/wechat
License: MIT License
微信 SDK for Laravel, 基于 overtrue/wechat
License: MIT License
我的控制器:
public function serve()
{
Log::info('request arrived.'); # 注意:Log 为 Laravel 组件,所以它记的日志去 Laravel 日志看,而不是 EasyWeChat 日志
$wechat = app('wechat');
//return $wechat;
app('wechat')->server->setMessageHandler(function($message){
return "欢迎关注 overtrue!";
});
Log::info('return response.');
return app('wechat')->server->serve();
}
我的route:Route::any('/weixin', 'WeixinController@serve');
我的middle:
protected $except = [
'weixin',
];
我的报告:BadRequestException in Guard.php line 317:
Invalid request.
我的日记:所有参数key,id等传输正确
腾讯验证:token验证错误
现在的写死了 5秒,只能通过修改源吗?
Laravel 5.1 可以配置 CSRF Except 路由了,这部分可以在 readme 里说一下配置方式。
local.ERROR: Overtrue\Socialite\AuthorizeFailedException: Authorize Failed: {"errcode":40013,"errmsg":"invalid appid, hints: [ req_id: tQPTEa0975s109 ]"} in /mnt/sdc/dindon_front/vendor/overtrue/socialite/src/Providers/AbstractProvider.php:409
Oauth 中间件, 网页授权的一直报这个错误。
如果直接使用 overtrue/wechat, 则会提示 secret 无效
php 版本:5.5.30
"overtrue/laravel-wechat":版本:3.0.6
使用微信对账单下载时候报错
$result=$payment->downloadBill(intval($request->input('date')));
ErrorException in XML.php line 37: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found
in XML.php line 37
at HandleExceptions->handleError('2', 'simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found', '/www/wwwroot/laravel/vendor/overtrue/wechat/src/Support/XML.php', '37', array('xml' => object(Stream)))
at simplexml_load_string('交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,企业红包金额,微信退款单号,商户退款单号,退款金额,企业红包退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率 `2016-03-14
大神你好
实例
//收到订阅事件
$server->on('event','subscribe',function($event){
$openID = $event->FromUserName;
$weChatUser = Wechat::user();
$userInfo = $weChatUser->get($openID)->toArray();
Users::create($userInfo);
return Message::make('text')->content('欢迎关注');
)}
就会报错:
FatalErrorException in Response.php line 0:
Method Overtrue\Wechat\Server::__toString() must not throw an exception
经过各种测试,只要是使用 Model::create() 方法就会这样, 在消息接收里也是这样。
我的Laravel 版本是 5.1
实在解决不了了,不知道哪里出的错。大神帮帮忙啊,多谢~~
最近发现一个问题。由于需要注册 ServiceProvider,导致一个问题。
即:最初引用本插件的开发者在config/app.php中注册了ServiceProvider,将代码提交到版本库后别的开发者更新下来,由于laravel默认是将vendor加入了git的忽略列表,因此其他开发者需要执行一次composer update才可能将插件安装,但是由于config/app.php已经注册了Overtrue\LaravelWechat\ServiceProvider,但此时Overtrue\LaravelWechat\ServiceProvider是不存在的,那么composer update将会报错,导致update无法执行。
对于这个问题,是否有更好的解决方案呢?
https://github.com/overtrue/socialite/blob/master/src/Providers/WeChatProvider.php#L117-L122
$response = $this->getHttpClient()->get($this->baseUrl.'/userinfo', [
'query' => [
'access_token' => $token->getToken(),
'openid' => $token['openid'],
],
]);
获取用户信息时没有提供lang参数,因此获取到用户所在城市、国家、省份信息是英文的。
大神,微信支付的接口涉及Business、 Order、UnifiedOrder、Payment四个对像,请问如何在 Controller 通过注入 或 Facade 获取实例?
代码如下:
$orderAttributes = [
'trade_type' => 'JSAPI',
'body' => '支付订单',
'out_trade_no' => Carbon::now()->format('ymdHisU'),
'total_fee' => bcmul($product->combo->price,100,0),
'notify_url' => url('xxx'),
'openid' => \Auth::user()->openid,
'attach' => sprintf('PAPA_%s_%s',$product->id,bcmul($product->combo->price,100,0)),
'device_info' => 'WEB',
'spbill_create_ip' => '8.8.8.8'
];
$order = new Order($orderAttributes);
$result = $wechat->payment->prepare($order);var_dump($result);
输出:
object(EasyWeChat\Support\Collection)#323 (1) {
["items":protected]=>
array(1) {
[0]=>
bool(false)
}
}
远端 HTTP CODE 200。response body 为空
现在支持laravel 5.3吗?
在路由中添加中间件:
5.2是这样的,5.3的路由该如何配置呢?
以 5.2 为例:
Route::group(['middleware' => ['web', 'wechat.oauth']], function () {
Route::get('/user', function () {
$user = session('wechat.oauth_user'); // 拿到授权用户资料
dd($user);
});
});
作者你好,我用composer安装时出现了以下问题,搜寻网上没有找到解决办法,请教如何解决
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.Problem 1
- Conclusion: don't install overtrue/laravel-wechat 3.0.1
- Conclusion: remove symfony/http-foundation v2.6.13
- Installation request for overtrue/laravel-wechat ~3.0 -> satisfiable by overtrue/laravel-wechat[3.0, 3.0.1].
- Conclusion: don't install symfony/http-foundation v2.6.13
- overtrue/laravel-wechat 3.0 requires overtrue/wechat ~3.0 -> satisfiable by overtrue/wechat[3.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4].
- overtrue/wechat 3.0 requires overtrue/socialite ^1.0 -> satisfiable by overtrue/socialite[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7].
- overtrue/wechat 3.0.1 requires overtrue/socialite ^1.0 -> satisfiable by overtrue/socialite[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7].
- overtrue/wechat 3.0.2 requires overtrue/socialite >=1.0.7 -> satisfiable by overtrue/socialite[1.0.7].
- overtrue/wechat 3.0.3 requires overtrue/socialite >=1.0.7 -> satisfiable by overtrue/socialite[1.0.7].
- overtrue/wechat 3.0.4 requires overtrue/socialite >=1.0.7 -> satisfiable by overtrue/socialite[1.0.7].
- overtrue/socialite 1.0.0 requires symfony/http-foundation ~2.8|~2.7 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3].
- overtrue/socialite 1.0.1 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.2 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.3 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.4 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.5 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.6 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- overtrue/socialite 1.0.7 requires symfony/http-foundation ~2.8|~2.7|~3.0 -> satisfiable by symfony/http-foundation[v2.7.0, v2.7.1, v2.7.10, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v3.0.0, v3.0.1, v3.0.2, v3.0.3].
- Can only install one of: symfony/http-foundation[v2.7.0, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.1, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.10, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.2, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.3, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.4, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.5, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.6, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.7, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.8, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.7.9, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.8.0, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.8.1, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.8.2, v2.6.13].
- Can only install one of: symfony/http-foundation[v2.8.3, v2.6.13].
- Can only install one of: symfony/http-foundation[v3.0.0, v2.6.13].
- Can only install one of: symfony/http-foundation[v3.0.1, v2.6.13].
- Can only install one of: symfony/http-foundation[v3.0.2, v2.6.13].
- Can only install one of: symfony/http-foundation[v3.0.3, v2.6.13].
- Installation request for symfony/http-foundation == 2.6.13.0 -> satisfiable by symfony/http-foundation[v2.6.13].
$media->download($value, $filename);
下载素材时出现下面问题。
[2015-04-30 18:52:31] local.ERROR: exception 'Overtrue\Wechat\Exception' with message '[Wechat][43002] 43002 需要POST请求' in /var/www/meishenghuo/web/vendor/overtrue/wechat/src/Wechat/Http.php:91
Stack trace:
#0 /var/www/meishenghuo/web/vendor/overtrue/wechat/src/Wechat/Utils/Http.php(65): Overtrue\Wechat\Http->request('http://file.api...', 'GET', Array, Array)
#1 /var/www/meishenghuo/web/vendor/overtrue/wechat/src/Wechat/Media.php(251): Overtrue\Wechat\Utils\Http->get('http://file.api...', Array)
#2 /var/www/meishenghuo/web/app/Http/Controllers/RepairsController.php(104): Overtrue\Wechat\Media->download('Gr31ecyJCdFhQK2...', '/var/www/meishe...')
我用laravel 5.1.11的版本,在微信公众平台的服务器配置中,做服务器验证时总提示Token验证失败,验证要怎么操作,大神指教!!!!
貌似企业号验证方式不一样,是否也支持?
感谢作者贡献此库,之前一直node,现在发现PHP库发送模板消息有点问题:
这两个部分对我们现在的应用场景蛮重要的,请问下应该修改库的什么部分来修复这两个问题呢,多谢!
如题,我看过代码,原因应该是VerifyTicket 的 cache 的 save() 方法没有给时间,即为 0,而 Laravel 的cache 的 put 方法是不考虑是不是 0 的,必须用 forever 方法。代码片段都在下面供参考。
测试过 database 和 redis 两个 cache driver。
VerifyTicket
public function cache(Collection $message)
{
return $this->getCache()->save(
$this->getCacheKey(),
$message->get($this->ticketXmlName)
);
}
DatabaseStore
public function put($key, $value, $minutes)
{
$key = $this->prefix.$key;
// All of the cached values in the database are encrypted in case this is used
// as a session data store by the consumer. We'll also calculate the expire
// time and place that on the table so we will check it on our retrieval.
$value = $this->encrypter->encrypt($value);
$expiration = $this->getTime() + (int) ($minutes * 60);
try {
$this->table()->insert(compact('key', 'value', 'expiration'));
} catch (Exception $e) {
$this->table()->where('key', $key)->update(compact('value', 'expiration'));
}
}
public function forever($key, $value)
{
$this->put($key, $value, 5256000);
}
RedisStore
public function put($key, $value, $minutes)
{
$this->connection()->setex(
$this->prefix.$key, (int) max(1, $minutes * 60), $this->serialize($value)
);
}
public function forever($key, $value)
{
$this->connection()->set($this->prefix.$key, $this->serialize($value));
}
Hello,
I'm trying to seta OAuth with WeChat on my app.
It seems the config file was not loaded, let see :
In the OAuthAuthenticate middleware, in the handle() function, you create a new $wechat like this :
$wechat = app('EasyWeChat\\Foundation\\Application');
But this error was thrown :
Unresolvable dependency resolving [Parameter #0 [ <required> $config ]] in class EasyWeChat\Foundation\Application
If I set the default param to empty array, and load the config file after like this :
public function __construct($config)
{
parent::__construct();
$config = config('wechat');
$this['config'] = function () use ($config) {
return new Config($config);
};
if ($this['config']['debug']) {
error_reporting(E_ALL);
}
$this->registerProviders();
$this->registerBase();
$this->initializeLogger();
Log::debug('Current configuration:', $config);
}
It works well.
PR was made : #30
PHP Parse error: syntax error, unexpected '{' in /home/wwwroot/weixin.xxx.com/vendor/overtrue/laravel-wechat/src/ServiceProvider.php on line 62
以下是我们运行的结果
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package overtrue/laravel-wechat could not be found in any version, there may be a typo in the package name.
Problem 2
- laravel/framework v5.0.28 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
- laravel/framework v5.0.28 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
- Installation request for laravel/framework == 5.0.28.0 -> satisfiable by laravel/framework[v5.0.28].
Potential causes:
Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
Installation failed, reverting ./composer.json to its original content.
已经按文档设置好了enable_mock和mock_user,并使用了wechat.oauth中间件,访问的时候还是提示需要在微信打开?
$wechat = App::make('wechat');
$wechat->on('message', ...);
在laravel 5 中报错 :[2015-04-19 03:19:04] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Undefined class constant 'User'' in /var/www/wechat/app/Http/Controllers/WechatController.php:22
请问这是为什么呢?
建议laravel版本直接增加redis配置
直接修改配置就能跟laravel自带redis整合一起
看到你文档写的做微信开发的时候必须要在CSRF验证中去除微信的路由,但是这样做我在测试中发现在Laravel5.2版本中是有问题的,原因如下:
根据Laravel文档我们可以设置$excerpt属性来排除部分不需要csrf的路由,但是我实际测试发现设置了也没用。查看csrf的源码如下:
public function handle($request, Closure $next)
{
if (
$this->isReading($request) ||
$this->runningUnitTests() ||
$this->shouldPassThrough($request) ||
$this->tokensMatch($request)
) {
return $this->addCookieToResponse($request, $next($request));
}
throw new TokenMismatchException;
}
从以上源码可以看到,if条件中四个只要满足一个就会执行这个中间件,第一个$this->isReading
方法的源码:
protected function isReading($request)
{
return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS']);
}
可以看到如果是HEAD
,GET
,OPTIONS
请求方法就不会执行$this->shouldPassThrough
这个方法来判定当前是否需要过CSRF中间件了。而且微信是GET和POST请求都有,所以我觉得在csrf中排除微信相关的路由这个做法有点不适合,你觉得呢?
lumen不支持session啊
Class wechat.server does not exist
很奇怪,其他都使用.唯独"wechat.server"提示不存在.
将下面代码,写到自带的"App\Providers\AppServiceProvider"却能使用.
$this->app->singleton(['Overtrue\\Wechat\\Server' => 'wechat.server'], function($app){
return new WechatServer(config('wechat.app_id'), config('wechat.token'), config('wechat.encoding_key'));
});
这是为什么???
在5.2中应该是,请更新readme谢谢
'Wechat' => Overtrue\LaravelWechat\Facade::class,
发现一个小问题,容器注释缺少门店注释,ide helpers没有捕获到
@overtrue
根据文档执行到$result = $payment->prepare($order);后,
打印$result的值,一直是返回只有false:
Collection {#944
#items: array:1 [
0 => false
]
}
也没有任何提示错误?还没找到是什么原因
像这种前后端完全分离的前端框架,原本网页授权的连续性被打破了,有没有好的方法去完成网页授权?
Class 'Overtrue\LaravelWechat\ServiceProvider' not found,所有文件到项目里,配置时没报错,执行php artisan vendor:publish报这个错
Hi, 我按照手册引入了相关的provider和facade。但是在controller中使用Wechat::时,报找不到相关的类。很迷惑哟~
Problem 1
- The requested package overtrue/laravel-wechat 2.0.* could not be found.
Potential causes:
Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
Laravel->5.4 fresh installed.
Laravel->wechat 3.2.4.
Project crashed if add Overtrue\LaravelWechat\ServiceProvider::class to providers array.
[ErrorException]
Illegal offset type in unset
如题
文档里说 “如果你用了 laravel-debugbar,请禁用或者关掉,否则这模块别想正常使用!!!”,请问不能同时使用debugbar的原因是什么?
使用中间件授权的方式。
某些手机授权不成功,拿不到openid.
user对象:
{
"id": null,
"name": null,
"nickname": null,
"avatar": null,
"email": null,
"original": {
"errcode": 40001,
"errmsg": "invalid credential, access_token is invalid or not latest, hints: [ req_id: aGWfma0000ns83 ]"
},
"token": {
"access_token": "p5rApFmJHpEzw37UIlwQNMnTMCxzksyrnp1fQGbcAxhCfrH5wGqFHI84SF6dDHhPCMs6J9DITF2br6gOxEEY2Hkzuw5qPjSnnuoK5uiw1zo",
"expires_in": 7200,
"refresh_token": "W9OZ31vZK0r5gCeMWiEOgXac-d23-CQZ3dBteZ93XWiqUAxgei9R9swNUKtYqdc9B9Zr98olV35LDsyaHoOwPxsHm61a-S7xW1WfIE8-NX0",
"openid": "oN-UTxF1XDoe-cs2MxUfedxUdX2Q",
"scope": "snsapi_userinfo"
}
}
微信公众号动态配置无效....
//
$wechatConfig = DB::table('wx_config')->first();
//...
//
$wechat = app('wechat', $wechatConfig);
$wechat['config']的值仍是config/wechat.php配置文件中的值,并不是传过去的$wechatConfig
[Overtrue\Wechat\Exception]
[Wechat]获取access_token时AppSecret错误,或者access_token无效。请开发者认真比对AppSecret的正确性,或查看是否正在为恰当的公众号调用接口
isNewSession等于true时,直接return 走了,Event::fire(new WeChatUserAuthorized(session('wechat.oauth_user'), $isNewSession));这里的isNewSesssion 永远不可能为true
非常棒的插件!已打赏!
我在更新2.x 到3.x的过程中,没有发现扫码支付中获得qr码的方式,您的schema已经准备好了,但是没有办法获得图片。请问这里是需要用第三方插件再次生成对吗?
https://easywechat.org/docs/zh-cn/payment.html#u751F_u6210_u5171_u4EAB_u6536_u8D27_u5730_u5740_JS__u914D_u7F6E
文档中也未体现获得qr码链接地址函数。
https://easywechat.org/zh-cn/docs/ 文档服务器挂了,建议能不能弄一个离线文档呢?
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.