天天看點

淘寶開放平台:消息推送接口問題一則

https://open.taobao.com/doc.htm?spm=a219a.7386653.0.0.120c669apt4vTq&docId=1&docType=15&apiName=taobao.tmc.messages.consume

訂單content.order_id是18位資料,在php轉換成json數組時,其值會變化,最後3位會替換成其他值(沒規律)。

解決辦法:

将order_id串替換成字元串再轉換成json。

//!! $content為stdObject,要轉換為array
$content = json_decode(json_encode($content),true);
$foo = $content['messages']['tmc_message'];
foreach($foo as $idx=>$item){
    $bar = preg_replace('/\\"order_id\\":(\d+),/','"order_id":"\1",',$item['content']);
    $foo[$idx]['content'] = json_decode($bar,true);
}      

轉載于:https://my.oschina.net/swingcoder/blog/3098389