Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mojo::Weixin 是否加入语音、视频、文件传输等功能 #28

Closed
linux0ne opened this issue Jul 31, 2016 · 25 comments
Closed

Mojo::Weixin 是否加入语音、视频、文件传输等功能 #28

linux0ne opened this issue Jul 31, 2016 · 25 comments
Labels

Comments

@linux0ne
Copy link

1、语音、小视频、GIF动画、动画表情、网页链接等,期待加入。
2、更为重要的一个——文件传输,呵呵。

网页版中有的功能若都实现的话,肯定要花费很多精力和时间,但如果真的要做的话,还是更一个图形界面的觉得更合适吧。

@linux0ne
Copy link
Author

linux0ne commented Aug 1, 2016

@KIDJourney
0x00、孩子,教教你:这叫——用户建议和反馈,不叫求。我的目的只有一个——让每个关注的项目都能更加的美好,尽自己所能去维护和丰富它。
0x01、你知道个6……你知道上面的内容是因为什么原因放在这里的?你知道它的目的是什么 ?你又知道谁建议放在这里的?不知不可怕,无知就太可怕了!
0x02、下次你再发言,请你就事论事。还有,再跟我说话,你客气点儿,别总尿叽的。我考虑够多,已经够给你留面儿了,懂吧!

@lyrl
Copy link

lyrl commented Aug 3, 2016

。。。。 你直接用微信客户端多好

@hexsum
Copy link
Owner

hexsum commented Aug 8, 2016

语音、小视频 已经支持
GIF动画、动画表情 开发中
网页链接 这个目前只能用文本的形式发送网页地址

@hexsum hexsum added the feature label Aug 8, 2016
@hexsum
Copy link
Owner

hexsum commented Aug 8, 2016

GIF动画、动画表情 已经完成

@hexsum hexsum closed this as completed Aug 8, 2016
@linux0ne
Copy link
Author

linux0ne commented Aug 9, 2016

@sjdy521
厉害! 加油!

@wsdjeg
Copy link

wsdjeg commented Oct 16, 2016

@KIDJourney block

@hexsum
Copy link
Owner

hexsum commented Oct 16, 2016

当前已经支持的 可以看下API.md里发送消息的部分,语音只能用文件的形式发送,图片、视频,其他文件也都支持发送

发自网易邮箱大师
在2016年10月16日 21:54,Wang Shidong 写道:

@KIDJourney block


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@wsdjeg
Copy link

wsdjeg commented Oct 16, 2016

@sjdy521 非常感谢,我刚刚接触这个项目,再多了解下。

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 28, 2016

@sjdy521 按照文档里面的发送视频:

#默认情况下,程序依靠文件扩展名或者url响应中的content-type等信息来识别媒体的格式,可能会导致识别不准确而影响发送
#这种情况下你可以传递一个hash的结构,手动指定媒体的相关信息
$client->send_media($friend|$group,{
    media_path => '/tmp/hello.txt', #媒体路径,可以是本地文件路径或者http协议的url
    media_data => 'hello world',    #可选,用于直接发送内存数据,优先级高于 media_path,
    media_mime => 'text/plain',     #可选,默认是 application/octet-stream,用于指定
    media_mtime => 1457169652 ,     #时间戳,文件修改时间,随意
    media_ext  => 'txt',            #文件扩展名
    media_size => 1024,             #可选,数据大小,默认会自动计算
    media_name => 'hello.txt',      #可选,媒体名称,默认是取文件名作为名称
});

这是我的代码:

                 $friend->send_media({
                    media_path => $commands[1],
                    media_mime => 'video/mpeg',
                    media_mtime => 1457169652 ,
                    media_ext  => 'mp4'
                  });

然后发送过去是文件,而不是直接可以看得视频。

@hexsum
Copy link
Owner

hexsum commented Dec 28, 2016

把media_mime去掉试试?

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 28, 2016

==

@hexsum
Copy link
Owner

hexsum commented Dec 28, 2016

我是根据mime里'video/mp4'来判断是视频文件,作为视频发送,你设置成了video/mpeg导致我会认为是普调文件,我已经在代码里兼容了 video/mpeg
你media_mime去掉的话,我会根据mp4的扩展名自动生成对应的media_mime,所以达到的效果是一样的
你可以先试试,基本上只需要设置media_path就行了,其他都可以不用管,会自动识别

@hexsum hexsum reopened this Dec 28, 2016
@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 28, 2016

哦,太好了,那我懂了。不过我这里老是502. 我回去用家里的网络试试。
[16/12/28 18:49:52] [warn] https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json 请求失败: 502 Bad Gateway
[16/12/28 18:49:52] [warn] media [ /tmp/7.mp4 ] upload failure

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 28, 2016

@sjdy521 , 我看到这个issue: liuwons/wxBot#99 说是微信上传文件的接口变了,由

https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json

变为了

https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json

请问这个链接在哪一个文件里面,我搜索不到,就不能替换测试.

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 28, 2016

一个kb级别的文件可以上传,但是2M的就不行了.

@hexsum
Copy link
Owner

hexsum commented Dec 28, 2016

@csrgxtu 你说的这个issue很老了,官方的接口变更过一次,但本项目早就同步更新过了
文件不能上传可能是有大小限制,可以使用网页版手动测试确认下
上传文件的代码在这里 https://github.com/sjdy521/Mojo-Weixin/blob/master/lib/Mojo/Weixin/Message/Remote/_upload_media.pm

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 29, 2016

文件大小是7.2M,使用send_media上传会出现如下:
image
使用网页版传输视频文件如下:
image

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 29, 2016

@sjdy521 我看了webwx,接口使用的是一样的,但是它发送的将文件分片发送的,依次做了如下请求:

OPTIONS https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json 多次
POST https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json  多次
POST https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendvideomsg?fun=async&f=json

/webwxuploadmedia的请求头部如下:

Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,zh-TW;q=0.2
Connection:keep-alive
Content-Length:526080
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryEULUqCcHOaa1IBCy
Host:file.wx2.qq.com
Origin:https://wx2.qq.com
Referer:https://wx2.qq.com/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

请问如何在下面代码中添加Content-Type

        $self->http_post(
            'https://file.' . $self->domain .'/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json',
            {json=>1,Referer=>'https://' . $self->domain . '/'},
            form=>{
                id=>'WU_FILE_0',
                name=>$msg->media_name,
                type=>$msg->media_mime,
                lastModifiedDate=>POSIX::strftime('%a %b %d %Y %H:%M:%S GMT+0800',gmtime($msg->media_mtime)),
                size=>$msg->media_size,
                mediatype=>(
                        $msg->media_type eq "image"                                             ?   "pic"
                    :   ($msg->media_type eq "video" or $msg->media_type eq "microvideo")       ?   "video"
                    :                                                                               "doc"
                ),
                uploadmediarequest=>$self->to_json($uploadmediarequest),
                webwx_data_ticket=>$self->search_cookie("webwx_data_ticket"),
                pass_ticket => $self->pass_ticket,
                filename =>{
                    content=>$msg->media_data,
                    filename=>$msg->media_name,
                    'Content-Type' => $msg->media_mime,
                },
            },
            sub{
                my $json = shift;
                if(not defined $json){
                    $self->warn("media [ ".$msg->media_path . " ] upload failure");
                }
                else{
                    $msg->media_id($json->{MediaId}) if $json->{MediaId};
                }
                $callback->($msg,$json);
            }
        );

@hexsum
Copy link
Owner

hexsum commented Dec 29, 2016

多谢分析,我这边也确认上传文件变成多次分块上传了,我马上修复下

hexsum added a commit that referenced this issue Dec 29, 2016
@hexsum
Copy link
Owner

hexsum commented Dec 29, 2016

@csrgxtu
千辛万苦总算搞定了,可以使用最新的github代码进行测试

1、微信上传文件最大限制20M,否则上传失败,api接口会给出超过大小限制提示

2、小于512K的文件会直接一次性上传
原先上传大文件,时间比较长,可能会导致api接口等待超时,把api接口的内部超时时间从15s改为120s,会有所有改善

3、大于512K的文件会自动按照512K分片依次上传,如果开启了debug日志会看到分片上传的过程,比如

[16/12/29 23:36:08] [debug] 正在上传媒体[xxx.mp4],当前进度:1/4
[16/12/29 23:36:10] [debug] 正在上传媒体[xxx.mp4],当前进度:2/4
[16/12/29 23:36:12] [debug] 正在上传媒体[xxx.mp4],当前进度:3/4
[16/12/29 23:36:13] [debug] 正在上传媒体[xxx.mp4],当前进度:4/4

另外,是否有兴趣成为这个项目的协作者(Collaborator)一起来完善这个项目

@csrgxtu
Copy link
Collaborator

csrgxtu commented Dec 30, 2016

@sjdy521 worked, tks very much. btw,我怎样才能成为collaborator, 我想成为贡献者。

@hexsum
Copy link
Owner

hexsum commented Dec 30, 2016

已经给你发邀请了 @csrgxtu

@hexsum hexsum closed this as completed Dec 30, 2016
@panzhc
Copy link

panzhc commented Apr 17, 2017

msg=$VAR1 = bless( {
'media_code' => 3,
'class' => 'recv',
'group_id' => '@@隐藏',
'time' => 1492424499,
'id' => '1559943971832219044',
'media_mtime' => 1492424502,
'media_size' => 0,
'media_ext' => 'html',
'media_name' => 'non-exist-path',
'format' => 'media',
'content' => '[图片]',
'media_type' => 'image',
'media_path' => 'non-exist-path',
'type' => 'group_message',
'media_mime' => 'text/html',
'media_data' => '',
'receiver_id' => '@隐藏',
'media_id' => '1559943971832219044:3',
'sender_id' => '@隐藏'
}, 'Mojo::Weixin::Message' );

path=$VAR1 = 'non-exist-path';
为什么有的图片会被识别成text/html? @sjdy521

@hexsum
Copy link
Owner

hexsum commented Apr 17, 2017

获取媒体文件失败(失败的原因就是服务端返回了text/html类型)也导致保存到本地文件失败,路径变成non-exists-path,暂时无法确定是服务端原因还是我代码兼容性问题

@panzhc
Copy link

panzhc commented Apr 18, 2017

谢谢回复,这个是间歇性的,有时候一天都正常,有时候又连续几个小时都non-exist-path,我再看下吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants