yunpian / yunpian-java-sdk Goto Github PK
View Code? Open in Web Editor NEWThe https://www.yunpian.com java sdk.
License: MIT License
The https://www.yunpian.com java sdk.
License: MIT License
common.Config.java中有强制重新设置log4j配置文件的static代码,建议去掉这块否则会对用户自身项目造成干扰,无法正常记录日志。
model包里面基础类都没有实现序列化接口,在分布式环境下,对这些类的实例进行传递时,会出问题
应该新增字段: error_detail
官网sdk的实例为什么和git不同步,还在用着YunpianRestClient,我在使用国际短信,搞不清楚你的API究竟是哪个?
look here:
http://mvnrepository.com/artifact/com.yunpian.sdk/yunpian-java-sdk
please update it.
服务器在美国,调用国内云片服务器会有很大延迟。使用jar包或maven可以如下覆盖配置项:
import java.util.Properties;
// ..........
Properties prop = new Properties();
prop.setProperty("yp.user.host","https://us.yunpian.com");
prop.setProperty("yp.sign.host","https://us.yunpian.com");
prop.setProperty("yp.tpl.host","https://us.yunpian.com");
prop.setProperty("yp.sms.host","https://us.yunpian.com");
prop.setProperty("yp.short_url.host","https://us.yunpian.com");
//初始化clnt,使用单例方式
YunpianClient clnt = new YunpianClient("5dd0287******apikey*****900441", prop).init();
Map<String, String> params = new HashMap<String, String>();
params.put("apikey", "xxxxxxxxxxxxxxxxxxx");
params.put("text", text);
params.put("mobile", mobile);
Result result = new SmsApi().single_send(params);
为什么会失败,失败的原因是YunpianApi 的uri()方法报空指针异常?还需要加什么参数呢?
根据接口文档,传了模版ID的时候,应该返回的是单个对象,不传时,返回的是一个数组。根据java-sdk里面的接口定义,两种情况下返回的都是数组。现在在传了模版ID之后会报json异常。
ResultDO{data=null, success=false, e=com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $}
public ResultDO<List<TemplateInfo>> get(final String tplId) {
return send(Config.URI_GET_TPL_SMS, new HashMap<String, String>() {{
put(YunpianConstants.TPL_ID, tplId);
}}, new TypeToken<List<TemplateInfo>>() {
}.getType());
}
public ResultDO<List<TemplateInfo>> get() {
return get("");
}
没有使用云片SDK之前,日志都在tomcat的logs目录下保存,单现在用了SDK,发现原先的配置没有用了,日志保存在tomcat目录下面了。
使用接口:指定模板单发
使用模板样式:【#company#】验证码#code#,您正在进行#option#,#eftime#有效。若非本人操作,请勿泄露。
请求参数:apikey=XXXXXXXXX&tpl_id=25525&mobile=139***********&tpl_value=#code#=1342&#eftime#=10%E5%88%86%E9%92%9F&#company#=%E4%BC%97%E5%BA%B7%E4%BA%91&#option#=%E6%BF%80%E6%B4%BB%E8%B4%A6%E6%88%B7
如果发送错误:解析出来的结果如下
发送成功用户收到的样式:
只替换掉了company,code两个变量,option和eftime没有替换成功。结果为:
【签名】验证码1523,您正在进行#option#,#eftime#有效。若非本人操作,请勿泄露。
上面为问题反馈,虽然可以通过单发接口发送想要的样式。遇到了还是给你们说下。
另外不得不吐槽下你们的售后,态度太牛逼了。
给它各种说明情况,叫给查一下问题,然后说自己弄的不对。最气的是最后来一句自己百度怎么替换变量。
没有简略的使用文档吗?我看了下基本上完全不兼容1.1.x了啊
用的是readme里面的方法发送:
//初始化clnt,使用单例方式
YunpianClient clnt = new YunpianClient("apikey").init();
//发送短信API
Map<String, String> param = clnt.newParam(2);
param.put(YunpianClient.MOBILE, "18616020***");
param.put(YunpianClient.TEXT, "【云片网】您的验证码是1234");
Result<SmsSingleSend> r = clnt.sms().single_send(param);
//获取返回结果,返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()
//账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*
//释放clnt
clnt.close()
只是内容中包含英文字母,就发送失败
RT
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.