WeChat gets chat history


Get chat history

1475200402638049.png

##In the chat records returned by this interface, images, voices, and videos are displayed in text formats of [image], [voice], and [video respectively. ]. For image messages that are more likely to contain important information, the image pull URL will be provided in the future and will be online in the near future.

Call instructions

##1
2
3
4
5
6
7
8
9
http request method: POST
https://api.weixin.qq.com /customservice/msgrecord/
getmsglist?access_token=ACCESS_TOKEN
POST data examples are as follows:
{
"starttime " : 987654321,
"endtime" : 987654321,
##"msgid" : 1,
##"number" : 10000
}

Parameter description

##Parameter DescriptionstarttimeStart time, unix timestamp#endtimeEnd time, unix timestamp, each query period cannot More than 24 hoursmsgidMessage id order is from small to large, starting from 1numberGet the number of items each time, up to 10,000

Return description

##1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19

20

21

#{
     
"recordlist" : [
         
{
       
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk",
                                   ##"opercode"
: 2002,
       "text" : " Hello, customer service test1 is at your service.",
                                                                                                                                                                                                                                                                                                   : "test1@test"
##                                                      
{                                                                                                    
"Opercode" : 2003,
## "Text"##: "Hello, what's the matter?"
,
## "Time" : 1400563731,##          
"worker"
: "test1@test"
       
}

    ],

     "number":2,

     "msgid":20165267


 }

Parameter Description

ParametersDescription
workerComplete customer service account, the format is: account prefix@public WeChat ID
openidUser ID
opercodeOperation code, 2002 (sent by customer service Message), 2003 (Customer service receives message)
textChat record
timeOperation time, unix timestamp

Return code description

##65400API is not available, that is, it has not been activated or upgraded to a new version Customer service function65416The query parameter is illegal65417The query time period exceeds the limit
Return codeExplanation

Call example

第一次
请求:
https://api.weixin.qq.com/customservice/msgrecord/getmsglist
?access_token=ACCESS_TOKEN
POST数据示例如下:
 
{
    
"starttime" : 1464710400,
    
"endtime" : 1464796800,
    
"msgid" : 1,
    
"number" : 10000
}
 返回:
{
    
"recordlist"
 
: [
       
{
          
"openid"
 
: 
"oDF3iY9WMaswOPWjCIp_f3Bnpljk"
,
          
"opercode"
 
: 2002,
          
"text"
 
: 
" 您好,客服test1为您服务。"
,
          
"time"
 
: 1464710500,
          
"worker"
 
: 
"test1@test"
       
},
       
{
          
"openid"
 
: 
"oDF3iY9WMaswOPWjCIp_f3Bnpljk"
,
          
"opercode"
 
: 2003,
          
"text"
 
: 
"你好,有什么事情?"
,
          
"time"
 
: 1464710600,
          
"worker"
 
: 
"test1@test"
       
},
         ......
    
],
     "number":10000,
     "msgid":20165258
}

请求的number(10000)和返回的number(10000)一样,该时间段可能还有聊天记录未获取,将msgid(20165258)填进下次请求中;

  第二次
请求:
https://api.weixin.qq.com/customservice/msgrecord/getmsglist
?access_token=ACCESS_TOKEN
POST数据示例如下:
 
{
    
"starttime" : 1464710400,
    
"endtime" : 1464796800,
    
"msgid" : 20165258,
    
"number" : 10000
}
返回:
{
    
"recordlist"
 
: [
       
{
          
"openid"
 
: 
"oDF3iY9WMaswOPWjCIp_f3Bnpljk"
,
          
"opercode"
 
: 2002,
          
"text"
 
: 
" 您好,客服test1为您服务。"
,
          
"time"
 
: 1464710700,
          
"worker"
 
: 
"test1@test"
       
},
       
{
          
"openid"
 
: 
"oDF3iY9WMaswOPWjCIp_f3Bnpljk"
,
          
"opercode"
 
: 2003,
          
"text"
 
: 
"你好,有什么事情?"
,
          
"time"
 
: 1464710800,
          
"worker"
 
: 
"test1@test"
       
},
         ......
    
],
     "number":4,
     "msgid":20165267
}

请求的number(10000)和返回的number(4)不一样,则该时间段的后续聊天记录获取完毕;