w7corp / easywechat Goto Github PK
View Code? Open in Web Editor NEW📦 一个 PHP 微信 SDK
Home Page: https://easywechat.com
License: MIT License
📦 一个 PHP 微信 SDK
Home Page: https://easywechat.com
License: MIT License
无法使用该回复消息类型
Fatal error: Uncaught exception 'Overtrue\Wechat\Exception' with message '
[Wechat]读取输入失败,请在 php.ini 中打开 always_populate_raw_post_data=On'
in /data1/www/htdocs/152/a327/1/third_party/Wechat/Server.php:200
Stack trace: #0 /data1/www/htdocs/152/a327/1/third_party/Wechat/Server.php(160):
Overtrue\Wechat\Server->prepareInput() #1 /data1/www/htdocs/152/a327/1/wechat.php(20):
Overtrue\Wechat\Server->serve() #2 {main} thrown in third_party/Wechat/Server.php on line 200
新浪的SAE下开发有一定限制,不能修改php.ini 想要部署在SAE上有解决的办法么?
2.0的AppSecret跑哪去了?怎么就变成了encodingAESKey?消息加密的密钥是必须的么?我记得AppSecret这个应用密钥是必须要的啊,1.0版本还有,2.0的版本怎么实例的时候就不用传了?现在用你2.0这类,微信老是未服务,我就纳闷那里奇怪,才发现这里好像有问题。求答复。。
原因在 overtrue\wechat\src\Wechat\Http.php 的 request() 中
$contents = json_decode($response['data'], true);
$response['data']
并不是json格式,是图片资源。
return $filename ? $contents : file_put_contents($filename, $contents);
要对换下冒号两边的参数 :
return $filename ? file_put_contents($filename, $contents) : $contents;
建议
将send的返回值,返回全部,不要只是msgid
{
"errcode":0,
"errmsg":"ok",
"msgid":200228332
}
回头方便调用者处理发送过程的结果(不是微信告知用户是否收到)
如题。谢谢。
回调是如何传递外部参数的?
通过关注者的微信号发送了一条消息,报错:
[2015-04-30 11:54:44] production.ERROR: exception 'Overtrue\Wechat\Exception' with message '[Wechat]Mcrypt 拓展未安装或未启用 系统繁忙,此时请开发者稍候再试' in /home/wwwroot/laravel/vendor/overtrue/wechat/src/Wechat/Crypt.php:63
打开这个文件看到:
if (extension_loaded('mcrypt')) {
throw new Exception('Mcrypt 拓展未安装或未启用');
}
如果 Session 中没有登录信息,则跳转到授权页并获取用户信息($auth->authorize() 一个方法全搞定)
文档上写着一个方法全搞定,这样自己还需要保存access_token或session吗?
$media = new Media(config('wechat.appId'), config('wechat.secret'));
$news = $media->lists('news', 0, 5);
这样使用有错吗。报错 : [Wechat][40004] 40004 不合法的媒体文件类型
[2015-07-13 12:53:59]|http:/xxx:80/listener/weixin/in?signature=09c15103416f24f04beaa890dc86284b7f54f6e3&echostr=4936468427967550941×tamp=1436763280&nonce=1194775519|140.207.54.79|||wx
signature => 09c15103416f24f04beaa890dc86284b7f54f6e3
echostr => 4936468427967550941
timestamp => 1436763280
nonce => 1194775519
[2015-07-13 12:53:59]|http:/xxx:80/listener/weixin/in?signature=09c15103416f24f04beaa890dc86284b7f54f6e3&echostr=4936468427967550941×tamp=1436763280&nonce=1194775519|140.207.54.79|||wx2
[2015-07-13 12:53:59]|http://xxx:80/listener/weixin/in?signature=09c15103416f24f04beaa890dc86284b7f54f6e3&echostr=4936468427967550941×tamp=1436763280&nonce=1194775519|140.207.54.79|||wx3
[false]
第一个是$_GET
第二个是$input = XML::parse($xmlInput);的$input
第三个是$this->input
这个SDK具体如何使用哦? 例如,新用户订阅,自动回复消息,是否有示例?单独用PHP没问题。
$this->wxServer->on('message', function($message) {
return Message::make('text')->content('您好!');
});
如何获取用户发来的信息呢?
比如我记录用户的信息日志
根据信息查询订单数据返回,类似智能回复
$message 这个?
如何能更好的扩展智能回复方案
Overtrue\Wechat\Http对JSON的识别存在问题,不能识别text/json
,我觉得可以用
textMIME = '~/json|text/plain~i'
public function attachExtension($cardId, array $extension = array()) { $timestamp = time(); $ext = array( 'code' => Arr::get($extension, 'code',''), 'openid' => Arr::get($extension, 'openid', Arr::get($extension, 'open_id','')), 'timestamp' => $timestamp, 'outer_id' => Arr::get($extension, 'outer_id',''), ); $ext['signature'] = $this->getSignature( $this->getTicket(), $timestamp, $cardId, $ext['code'], $ext['openid'] ); return array( "cardId" => $cardId, "cardExt" => JSON::encode($ext), ); }
之前返回的是 card_id,card_ext 界面显示不出卡券信息,改成cardId,cardExt就可以了
require "./autoload.php";
use Overtrue\Wechat\Server;
$appId = 'myapp';
$token = 'testtoken';
$encodingAESKey = 'myaeskey';
$server = new Server($appId, $token, $encodingAESKey);
$server->on('message', function($message){
return "您好!欢迎关注 overtrue!";
});
为什么用户给公众号发消息却收不到“您好!欢迎关注 overtrue!"“
使用微信公众号进行开发时也常常会用到微信js,是否考虑添加微信js的功能呢?
通过refresh_token重新获取用户access_token,auth.php没做实现吗?
有一种业务场景:
1、用户一个月前网页授权过了,我这也存了用户的性别、昵称等等
2、用户最近更改了微信昵称,他发现我的网站个人信息页面昵称还是以前的
这种情况我想重新获取用户信息,按照auth逻辑,是不是要重新让用户跳转授权页面确认
而不是通过refresh_token重新获取用户access_token,然后自动获取最新的用户信息
错误提示如下:
PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
PHP Warning: Cannot modify header information - headers already sent in Unknown on line 0
我换成了php5.5版本后错误消失
PHP Parse error: syntax error, unexpected '{' in /home/wwwroot/weixin.xxx.com/vendor/overtrue/laravel-wechat/src/ServiceProvider.php on line 62
今天开始,授权时候一直报40029,invalid code的错误,是我配置错误还是使用错误???之前一直很好的在使用,没有问题。。。BTW,谢谢楼主分享这个包
public function config(array $APIs, $debug = false, $json = true,$beta = false)
{
$signPackage = $this->getSignaturePackage();
$config = array_merge(array('debug' => $debug),array('beta' => $beta), $signPackage, array('jsApiList' => $APIs));
return $json ? JSON::encode($config) : $config;
}
针对设备的 api 中有 beta 这个属性……
Call to undefined function Overtrue\Wechat\mcrypt_module_open() in ... vendor/overtrue/wechat/src/Wechat/Crypt.php on line 195
这个好奇怪,怎么namespace会调用到Overtrue\Wechat\
public function user() { if ($this->authorizedUser || !$this->input->has('state') || (!$code = $this->input->get('code')) && $this->input->has('state')) { return $this->authorizedUser; } $permission = $this->getAccessPermission($code); if ($permission['scope'] !== 'snsapi_userinfo') { $user = new Bag(array('openid' => $permission['openid'])); } else { $user = $this->getUser($permission['openid'], $permission['access_token']); } return $this->authorizedUser = $user; }
您好,当access_token过期时使用accessTokenIsValid时需要access_token和刷新使用refresh_token,而
$user = new Bag(array('openid' => $permission['openid']));
个人觉得还是有作用的,有没有点tip,提示一下:如何在已有的SDK基础上修改开发
$news = Message::make('news')->items(function ()
{
for ($i = 0; $i < 4; $i++){
$list[$i] = Message::make('news_item')->title($data[$i]['title'])
->description('我的太难啊')
->url('http://www.baidu.com')
->picUrl('http://zxpic.gtimg.com/infonew/0/wechat_pics_-711632.jpg/640');
}
return $list;
});
超超我想提个建议,能否在Media类里面加个get方法,
通过media_id从微信获取素材实例,并且它可以当做news_item直接来使用?
例如:
$config = [...];
$media = new Media($config);
$collection = [...];
$items = [];
foreach ($collection as $data) {
$items[] = $media->get($data->remote_media_id)->toNewsItem();
}
return Message::send('news')->items($items);
其实并不明白加这段代码的作用
https://github.com/overtrue/wechat/blob/master/src/Wechat/Utils/Http.php#L267-276
从结果上说,这使得双引号在Util\JSON::encode()执行期间躲起来了。
一个情景是图文信息是可以使用HTML的,content中的双引号就杯具了QAQ
$src = '""';
var_dump(urlencode($src)); // string '%22%22' (length=6)
var_dump(urldecode(urlencode($src))); // string '""' (length=2)
已经支持oauth打开页面获取用户信息了吗?
修改图文信息的方法
https://github.com/overtrue/wechat/blob/master/src/Wechat/Media.php#L179
'articles' => array($article)
对传入的数组又放入了一个新的数组中。
微信API: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
示例如下:
{
"media_id":MEDIA_ID,
"index":INDEX,
"articles": {
"title": TITLE,
"thumb_media_id": THUMB_MEDIA_ID,
"author": AUTHOR,
"digest": DIGEST,
"show_cover_pic": SHOW_COVER_PIC(0 / 1),
"content": CONTENT,
"content_source_url": CONTENT_SOURCE_URL
}
}
注意articles键的值是一个关联数组。
也就是说发布图文消息时$article的结构是[{},{},{}],在更新时只能根据index更新各项{}。
我因为只需要发单图文信息,直接把[]去掉就可以了。
对于需要编辑多图文的客户端代码,确实有可能忘记提取元素(我一开始也写成发布和更新传入的参数一样,改了以后发现还是不对才去看的源码),感觉这样就可以偷懒了?
$article = isset($article['title']) ? $article : (isset($article[$index]) ? $article[$index] : throw something);
3.1
3.1
3.1
stripos($mime,
/json)
背景:
1、token验证成功
2、菜单创建也可成功
3、发送文本后显示为”该公众好无法提供服务“
代码部分如下
$token = '111';
$encodingAESKey = 'bLRZ3sB3n2wyWnkUXv0nn9a9SvMiokpmjWxwwq6QbLt';
$server = new Server($appId, $token,$encodingAESKey);
$server->on('message', function($message) {
return Message::make('text')->content('您好!');
});
$result = $server->serve();
echo $result;</code>
"first" => array("恭喜你购买成功!", '#555555'),
类似这样的格式无效,会导致发送的参数为空
[value=>'',color='']
这样的格式就可以,麻烦看看呢
目前图片上传后返回的xml已经不仅仅是media_id了,还有url,求加上哟~
$options = array(
'appId' => 'xxxx',
'secret' => 'xxxxxx'
'token' => 'xxxx',
'encodingAESKey' => 'xxx'
);
$wechat = Wechat::make($options);
$wechat->on('message', function($message) {
return Message::make('text')->content('您好!'.$message->FromUserName);
});
$result = $wechat->serve();
echo $result;
我这么写了,可是网页上出现下面这个错误
Fatal error: Using $this when not in object context in /var/www/html/wwhis.com/www/src/Wechat/Wechat.php on line 113
Hi,
我在菜单事件时,用的例子里的代码如下:
// 监听所有事件
$server->on('event', function($event) {
error_log('收到取消关注事件,取消关注者openid: ' . $event['FromUserName']);
});
打印收到的signature,time和nonce正常, xml内容也正常,但是提示异常:
[2015-07-31 04:41:20] local.ERROR: exception 'Overtrue\Wechat\Exception' with message '[Wechat]Bad Request' in /home/workplace/weixin_date/vendor/overtrue/wechat/src/Wechat/Server.php:171
你好 我根据wiki里面的示例 第一次授权可以获得用户信息 但是只要刷新就会出现40029,能帮我分析一下问题吗?
if ($auth->authorized() || Session::get('logged_open_id')) {
$user = $auth->user();// 获取已经登录后用户信息
Session::set('logged_open_id', $user['open_id']);
//code 显示授权后的页面,或者跳转到其它授权才能访问的页面
//...
} else {
$to = "http://微信授权完成后跳回你的地址,就是当前代码所在的 URL";
$auth->redirect($to);
}
appId secret token encodingAESKey 4者都填写正常,微信后台还是报“token验证失败。” 能给一个示例么? 谢谢。
hi ,overtrue,成功使用wechat框架在微信内绑定H5系统内的用户后(用户表存放openid),现在需要在微信内判断如果用户已经绑定过openid,则自动登陆。现在的情况是,H5使用Ajax取值时,初次调用$auth->authorize()会服务端会重定向,导致H5端无法取值,这种情况要怎么处理呢?
下载图片出现如下错误 :
有的图片能下载,有的图片不能下载的情况。
错误如下:
[2015-05-04 10:47:47] local.ERROR: exception 'ErrorException' with message 'Undefined offset: 1' in /var/www/meishenghuo/web/vendor/overtrue/wechat/src/Wechat/Utils/Http.php:228
我的解决方法如下,但是不知道这样做对不(能解决部分图片不能下载问题)。
Wechat\Utils\Http.php的 request() 方法下 :
$responseSplit = preg_split('/((?:\r?\n){2})/', $response['response']);
正则分割 header和 body的时候出现了 body被拆分成两部分的情况(本该是
$responseSplit = array(0=>"header信息", 1=>"body信息");
结果变成
$responseSplit = array(0=>"header信息", 1=>"body1信息", 2=>"body2信息");
)。
我把正则内的 \r 后面的 ? 问号去掉就能解决问题(不懂为什么)。
$responseSplit = preg_split('/((?:\r\n){2})/', $response['response']);
用作日志监控等
也可以方便以后微信拓展新的msgtype类型
以下为php代码
$config = array( 'use_alias' => false, 'app_id' => WxPayConfig::APPID, 'secret' => WxPayConfig::APPSECRET, 'token' => WxPayConfig::APPTOKEN, 'encoding_key' => WxPayConfig::ENCODING_KEY // 加密模式需要,其它模式不需要 ); $js = new Js($config); $card = new Card($config); $timestamp = time(); $nonce_str = $card->getNonce(); $api_ticket = $card->getTicket(); //根据http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=cardsign 来看需要appid和cardType $signature = $card->getSignature($api_ticket, $timestamp, WxPayConfig::APPID, 'CASH', $nonce_str);以下为js代码
wx.config(<?php echo $js->config(array('chooseCard'), true, true) ?>); wx.ready(function () { document.querySelector('#chooseCard').onclick = function () { wx.chooseCard({ cardType: 'CASH', //需要与卡券签名传入参数保持一致 timestamp: <?php echo $timestamp ?>, // 卡券签名时间戳 nonceStr: '<?php echo $nonce_str ?>', // 卡券签名随机串 cardSign: '<?php echo $signature ?>', // 卡券签名 success: function (res) { alert(res); var cardList= res.cardList; // 用户选中的卡券列表信息 } }); } });
我把
$this->wxServer->on('message', function($message) {;
$this->msgLog($message->toArray());
return Message::make('text')->content('hello!');
});
$this->wxServer->on('event', function($event) {;
$this->eventLog($event->toArray());
});
消息和事件处理写在一个页面,当有事件请求的时候,怎么还进入了消息处理逻辑?
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.