与第三方之间做接口对接时,对方采用的是C#编写的,而我用的是PHP。在使用md5加密验证时,一直提示加密字段不正确。根据接口文档提示,试了很多办法将php转为unicode,但还是不行。后来通过搜索发现了正确答案。
mb_convert_encoding( $str,'UTF-16LE','UTF-8')
回去查了下手册,发现iconc函数也可以达到此目的。
iconv
iconv($in_charset,$out_charset,$str)
将字符串$str从 in_charset转换编码到out_charset
in_charset输入的字符集;out_charset 输出的字符集;str要转换的字符串
返回值:返回转换的字符串,或者在失败时返回FALSE
mb_convert_encoding
mb_convert_encoding($str,$to_encoding,$from_encoding)
将string类型的str从可选的from_encoding转换为to_encoding
返回值:编码后的string









网友评论