Comments (18)
贴你的代码
from laravel-wechat.
贴你的代码
基本就是根据 readme 文档写的。vendor 目录有删掉重新 install
// 路由 :
Route::any('/wechat', [\App\Http\Controllers\WeChatController::class, 'serve']);
Route::group(['middleware' => ['web', 'wechat.oauth:default,snsapi_userinfo']], function () {
Route::get('/user', function () {
$user = session('wechat.oauth_user.default'); // 拿到授权用户资料
dd($user);
});
});
<?php
namespace App\Http\Controllers;
use Log;
class WeChatController extends Controller
{
/**
* 处理微信的请求消息
*
* @return string
*/
public function serve() // 这里不能有 : string
{
Log::info('request arrived.'); # 注意:Log 为 Laravel 组件,所以它记的日志去 Laravel 日志看,而不是 EasyWeChat 日志
$app = app('wechat.official_account');
$app->server->push(function($message){
Log::info(__FILE__.'::'.__LINE__, func_get_args());
return "欢迎关注 overtrue!";
});
return $app->server->serve();
}
}
对了,我用的是测试公众号, 不过应该不影响才对
https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
from laravel-wechat.
用浏览器测试呢?
from laravel-wechat.
![image](https://private-user-images.githubusercontent.com/1472352/334333271-4eede7e5-0b29-4ae5-b663-29a2d3c03e18.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5OTcwNjgsIm5iZiI6MTcyMzk5Njc2OCwicGF0aCI6Ii8xNDcyMzUyLzMzNDMzMzI3MS00ZWVkZTdlNS0wYjI5LTRhZTUtYjY2My0yOWEyZDNjMDNlMTgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MThUMTU1OTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OGI2ODBmY2VkZDljYTQ3NTY0N2NiZWYyYTQ1ZDJiZGY1NzMzNjAxNTkyMjQwZGYwOWQ2ZGRiMWI1ZjBhODBmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.O-BOIfcrz2LdwLVUnMDN59BgN_MvCr2sfGhkoOSI_LI)
from laravel-wechat.
原生和美化是一样的
curl 我也试了, 有 2 个 http,
from laravel-wechat.
我打算试下laravel 9.x 的原始版本, 看看行不行
from laravel-wechat.
所以现在是什么版本?
from laravel-wechat.
所以现在是什么版本?
overtrue/laravel-wechat: 6.2.0
w7corp/easywechat: 5.35.1
laravel: v9.52.16
# git reset --hard origin/9.x
php artisan serve
curl -i 'http://127.0.0.1:8000/wechat?echostr=5314236442487000783&nonce=2036361721&signature=ea5ec21b511a1731c0988b84d367a6cfe64bb876×tamp=1716881487'
问题还是存在
from laravel-wechat.
跟这个输出挺像的
from laravel-wechat.
那不是你自己打印的么……
from laravel-wechat.
我本地重新装了一个项目没法复现。
from laravel-wechat.
应该是你自己改了啥代码导致的
from laravel-wechat.
应该是你自己改了啥代码导致的
App\Http\Controllers\WeChatController
这个类的内容是什么?
我用laravel 官网下的源码也是有这个问题, 不知道是不是源的问题。我重新下载一下试试
php : 8.1.25
from laravel-wechat.
应该是你自己改了啥代码导致的
接口没有手动打印, 那个是 测试的命令行
重新拉取 也是不行
php : 8.1.25
laravel: 9.52.16
overtrue/laravel-wechat: 6.2.0
w7corp/easywechat: 5.35.1
我找找其他吧
from laravel-wechat.
return $app->server->serve();
// 这段代码改成下面的就可以了
return $app->server->serve()->getContent();
什么情况
from laravel-wechat.
把项目全删了,重新换个名字的目录重装
from laravel-wechat.
把项目全删了,重新换个名字的目录重装
我重新下载的 laravel 还是一样, 哪个环节的问题,正常不应改这样啊
git clone https://github.com/laravel/laravel.git laravel-testt
git checkout -b 9.x origin/9.x
git log -2
# commit 5b60b604c4167b30286a6e033723a6b274e8452d (HEAD -> 9.x, origin/9.x)
php -v
#PHP 8.1.27 (cli) (built: Dec 19 2023 23:26:33) (NTS Visual C++ 2019 x64)
composer install
composer require overtrue/laravel-wechat
# 该路由、WeChatController、 http\kernel 等
php artisan route:list
# ANY wechat .......WeChatController@serve
curl -i 'http://127.0.0.1:8000/wechat?echostr=5314236442487000783'
可以想到的都改了, 试试 xdebug 了
from laravel-wechat.
把项目全删了,重新换个名字的目录重装
找到原因了, 谢谢
最近用 laravel/pint 比较多,习惯性的设置返回值,这里搞错了,
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class WeChatController extends Controller
{
/**
* 处理微信的请求消息
*
* @return string
*/
public function serve(): SymfonyResponse // string 习惯性的就放下来了, 就返回字符串
{
}
}
是我的粗心, 后面我看看改成什么
再次感谢作者。
from laravel-wechat.
Related Issues (20)
- openssl_sign()
- laravel-wechat 如何根据 [w7corp/easywechat] 进行API 调用 HOT 1
- /tmp/easywechat/easywechat.log HOT 1
- php8.2有问题 HOT 4
- 公众号: 超时重试问题
- Laravel 10 安装发布资源报错 HOT 5
- $message 变量为空 无法接收到消息
- 为什么验证会报这个错误?laravel 9, php8.1 HOT 1
- laravel10安装报错 HOT 1
- 获取access_token过期之后不自动刷新 HOT 1
- Laravel 8.75 安装失败 HOT 1
- octane 服务下接收不到支付回调 HOT 2
- 与laravel 10 冲突,主要是monolog的版本冲突 HOT 3
- Laravel 10 无法安装 7.2 版本的 overtrue/laravel-wechat HOT 1
- 企业oauth方法报错:No suite_ticket found.
- laravel 10 安装的"overtrue/laravel-wechat": "7.2" 请求JSAPI 下单接口报错 HOT 1
- 给公众号发消息,一直没有响应,没返回任何内容 HOT 13
- Laravel10 安装报错 HOT 4
- overtrue/laravel-wechat 和包w7corp/easywechat依赖? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-wechat.