php生成不同格式的json,请教关于 PHP 的 json_encode 问题,是不是它的格式跟 Python , Java 生成的有些不一样?...

以下是一个 soap 的接口,往该接口的 funMain 方法上,传输一个 json,就可以发送短信了。这个是 php 的代码,显示失败

$url = 'http://***/wsApi?wsdl';

$content=’ this is a test message';

$funcode = '1002'; //自定义扩展代码(模块)

$ApplicationID = 'HsqjSYsn6QjTrqzdW'; //账号

$Password = '6VnLZlVwKf'; //密码

$paras = array(

'content' =>$content,

'funCode' =>$funcode,

'applicationId' =>$ApplicationID,

'password' =>$Password);

$sendInfo=array(

'sendId' =>'0',

'mobile' =>'18899990000'); //手机号码

$paras['sendInfo'] ][0]=$sendInfo;

$client = new soapclient($url);

$result=$client->funMain(json_encode($paras));

而用 python,是没有问题的。

import sys

import json

import suds

from suds.client import Client

url='http://***/wsApi?wsdl'

c=Client(url)

def sms(phonenumber,text):

data={\

'applicationId': 'HsqjSYsn6QjTrqzdW5K',\

'password': '6VnLZlVw',\

'funCode': '1002',\

'content': 'this is for what you want to sent',\

'sendInfo': [\

{\

'sendId': '0',\

'mobile': '188990000'\

}\

]\

}

data['content']=text

data['sendInfo'][0]['mobile']=phonenumber

d=json.dumps(data)

e=c.service.funMain(d)

if __name__=='__main__':

if len(sys.argv)!=3:

print ('Usage:python need 2 string')

exit(1)

phonenumber=sys.argv[1]

text=sys.argv[2]

try:

sms(phonenumber,text)

except:

print ('duanxinji failure')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值