支付宝即时到帐接口的编码问题

作者:Hily 原始链接:http://hily.me/blog/2009/08/alipay-encoding-problem/
版权声明:可以转载,转载时务必以超链接形式标明文章原始出处作者信息版权声明

官方的示例代码写得很有问题,最好自己检查一遍。

其中有一段:

// 实现多种字符编码方式
    function charset_encode($input,$_output_charset ,$_input_charset ="GBK" ) {
        $output = "";
        if(!isset($_output_charset) )$_output_charset  = $this->parameter['_input_charset '];
        if($_input_charset == $_output_charset || $input ==null) {
            $output = $input;
        } elseif (function_exists("mb_convert_encoding")){
            $output = mb_convert_encoding($input,$_output_charset,$_input_charset);
        } elseif(function_exists("iconv")) {
            $output = iconv($_input_charset,$_output_charset,$input);
        } else die("sorry, you have no libs support for charset change.");
        return $output;
    }

而调用 charset_encode 时使用的 _output_charset 参数居然是 _input_charset,简直是乱套!

另外,这段代码中$this->parameter['_input_charset '];,居然在 _input_charset 后面加了个空格,写这段程序的人实在太没有责任心了!

我修改后,把 _output_charset 和 _input_charset 都设置成了 utf-8,却发现支付页面在 IE6 下变形,估计是 UTF-8 BOM 的问题了,希望支付宝赶紧修复这方面的问题。

-- EOF --

已经有 2 条评论 »

  1. Hily 说道:

    2009年08月23日 17:18

    原来API里的 _input_charset 指的是提交给接口的参数编码,和 charset_encode 里的 _input_charset 一点儿关系都没有,混淆了!

    UTF8版,把function charset_encode($input,$_output_charset ,$_input_charset ="GBK" ) 中的 $_input_charset ="GBK" 改成 $_input_charset ="UTF-8" 就正常了。

  2. 豆腐 说道:

    2009年10月01日 21:55

    哈哈 ,我们用gbk的 应该不会又问题吧。。

发表一下您的高见

If you have any question, or for the language problem, please fell free to leave a comment or just contact me with email: hilyjiang [At] Gmail.