1002 错误 同样的代码 ,发送英文消息可以,但发送中文失败

1002
error
标签: #<Tag:0x00007fb84dab81c0> #<Tag:0x00007fb84dab8058>

(billy) #1

JPush技术人员,您好。我在使用JPush的接口时,同样的代码,在消息体中,即alert字段中,写英文信息,是可以推送到手机的。但alert中,填中文,就失败,返回的结果提示:
{“error”: {“message”: “Missing parameter”, “code”: 1002}}

英文成功:2016-12-02 13:34:00
内容:This is english test

中文失败:2016-12-02 13:35:00
内容:这是中文测试

APPKey:972dff84b888dda37ce5af80

还请官方技术人员帮忙看看,您们那边得到的数据是怎样的。 十分感谢!


#2

你提供一下出现1002错误的请求的json串,完整的


(billy) #3
  CONCATENATE
 ' {'
   '"platform": ['
  '   "android",'
  '   "ios"'
  ' ],'
  ' "audience": {'
  '   "registration_id": ['
  '     "160a3797c80bbcb7d42"' "Billy's Mob No.
  '   ]'
 '  },'
  ' "notification": {'
  '   "android": {'
  '     "alert": "这是中文测试",'
  '     "title": "Send to Android",'
  '     "builder_id": 2,'
  '     "extras": {'
  '       "newsid": 321'
  '     }'
  '   },'
  '   "ios": {'
  '     "alert": "Greetings from SAP!",'
  '     "sound": "default",'
  '     "badge": "+1",'
  '     "extras": {'
  '       "newsid": 321'
  '     }'
  '   }'
  '},'
  ' "options": {'
  '   "apns_production": false'
  ' }'
 '}'
 INTO wf_string. 

这个是一种叫ABAP的语言, 语法可能有点不一样,不过您可以看alert里面,现在里面写的是:这是中文测试 。 如果换成英语,则可以发送成功!


#4

这里注意到了吗?


(billy) #5

CALL METHOD http_client->request->set_header_field
EXPORTING
name = ‘Content-Type’
value = ‘application/json; charset=UTF-8’.

这是设置header的代码。

还是说, 我要把“这是中文测试”, 这六个字先转码? 转成&#x8FD9;&#x662F;&#x4E2D;&#x6587;&#x6D4B;&#x8BD5; 再发送?

那就是代码变成:

’ “notification”: {’
’ “android”: {’
’ “alert”: “&#x8FD9;&#x662F;&#x4E2D;&#x6587;&#x6D4B;&#x8BD5;”,’
’ “title”: “Send to Android”,’
’ “builder_id”: 2,’
’ “extras”: {’
’ “newsid”: 321’
’ }’
’ },’

是这样么?


(billy) #6

哦 Content-Type 可能没设置对,我试试


(billy) #7
CONCATENATE
 ' {'
   '"platform": ['
  '   "android",'
  '   "ios"'
  ' ],'
  ' "audience": {'
  '   "registration_id": ['
  '     "160a3797c80bbcb7d42"' "Billy's Mob No.
  '   ]'
 '  },'
  ' "notification": {'
  '   "android": {'
  '     "alert": "则是中文1ii",'
  '     "title": "Send to Android",'
  '     "builder_id": 2,'
  '     "extras": {'
  '       "newsid": 321'
  '     }'
  '   },'
  '   "ios": {'
  '     "alert": "Greetings from SAP!",'
  '     "sound": "default",'
  '     "badge": "+1",'
  '     "extras": {'
  '       "newsid": 321'
  '     }'
  '   }'
  '},'
  ' "options": {'
  '   "apns_production": false'
  ' }'
 '}'
 INTO wf_string.

  CLEAR :rlength , txlen .
  rlength = strlen( wf_string ) .
  MOVE: rlength TO txlen .

  CALL METHOD cl_http_client=>create
    EXPORTING
      host          = 'api.jpush.cn'
      service       = '443'                       " <<-----  443 NOT 80
      scheme        = '2'                        "https
      ssl_id        = 'ANONYM'              " <<----- SSL_ID Added
    IMPORTING
      client        = http_client.


  http_client->propertytype_logon_popup = http_client->co_disabled.
    CALL METHOD http_client->authenticate
    EXPORTING
      username             = '972dff84b888dda37ce5af80'
      password             = '************************'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'POST'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_protocol'
      value = 'HTTP/1.0'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_uri'
      value = '/v3/push'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'Content-Type'
      value = 'application/x-www-form-urlencoded; charset=UTF-8'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'Content-Length'
      value = txlen.

  call method http_client->request->set_header_field
    exporting
      name  = 'HOST'
      value = 'api.jpush.cn'.

  CALL METHOD http_client->request->set_cdata
    EXPORTING
      data   = wf_string
      offset = 0
      length = rlength.

  CALL METHOD http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.

  CLEAR wf_string1 .

  wf_string1 = http_client->response->get_cdata( ).

(billy) #8

这是所有核心代码, 设置了Content-type还是不行, 能帮忙看看后台么, 反正英文是可以的,中文确不行。


#9

这个是你推送的代码,你看一下你推送之后的服务端日志里面的 请求的json串 ,把他贴出来。

我们这边要查这类信息的话要去找后台,手续也比较繁琐,所以咱先查一下你的json串


(billy) #10

嗯 好的 那我先想办法查下我这边的日志,再给您回复


(billy) #11

问题已经解决,我们自己的代码,计算长度(Content-Length)的地方弄错了,现在已经解决了。谢谢!