search
Homephp教程php手册关于PHPFetion不能给好友发送飞信的问题

关于PHPFetion不能给好友发送飞信的问题

Jun 06, 2016 pm 08:07 PM
cannotaboutsendfriendsnew versionquestionFetion

(最新版本下载:http://code.google.com/p/php-fetion/downloads/detail?name=phpfetion_v1.3.0.zip) 最近一直有网友反映,PHPFetion类不能给好友发送飞信了,但给自己还可以。通过网友的提示以及我自己的研究发现,在wap飞信中给好友发信息时,加了个csrf

(最新版本下载:http://code.google.com/p/php-fetion/downloads/detail?name=phpfetion_v1.3.0.zip)

最近一直有网友反映,PHPFetion类不能给好友发送飞信了,但给自己还可以。通过网友的提示以及我自己的研究发现,在wap飞信中给好友发信息时,加了个csrfToken字段。

不出意料的话,这个csrfToken应该就是起个防止表单跨站提交的作用。但由于这个csrfToken明文出现在了给好友发飞信的表单页面里,所以获取它也很容易。并且这个csrfToken在给其他任何好友发飞信时,都是不变的,所以只需要获取一次即可。

我写了如下代码来获取csrfToken:

/**
 * csrfToken
 * @param string
 */
protected $_csrfToten = null;
/**
 * 获取csrfToken,给好友发飞信时需要这个字段
 * @param string $uid 飞信ID
 * @return string
 */
protected function _getCsrfToken($uid)
{
    if ($this->_csrfToten === null)
    {
        $uri = '/im/chat/toinputMsg.action?touserid='.$uid;
        $result = $this->_postWithCookie($uri, '');
        preg_match('/name="csrfToken".*?value="(.*?)"/', $result, $matches);
        $this->_csrfToten = isset($matches[1]) ? $matches[1] : '';
    }
    return $this->_csrfToten;
}

另外也修改了给好友发飞信的_toUid()函数:

/**
 * 向好友发送飞信
 * @param string $uid 飞信ID
 * @param string $message 短信内容
 * @return string
 */
protected function _toUid($uid, $message)
{
    $uri = '/im/chat/sendMsg.action?touserid='.$uid;
    $csrfToken = $this->_getCsrfToken($uid);
    $data = 'msg='.urlencode($message).'&csrfToken='.$csrfToken;
    $result = $this->_postWithCookie($uri, $data);
    return $result;
}

写好的代码依然放在了Google Code中,并打包成了最新版本PHPFetion v1.3,下载地址为:http://code.google.com/p/php-fetion/downloads/list。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.