在使用/op接口之前,先阅读接口API文档,
点击查看/op的API接口文档
如下图所示:
交易纪录数据结构为:token_x op(sms) token_y opval(phone and code) extra_data ;(非转帐推荐使用assert、config、notice等指令)
一般情况下,除非是send消息,令token_x=coin_0000000000000000(即token_root)
令token_y=coin_6dgscloudsms0001(我们使用上面fork接口API创建的token-id)
#1 发送短信须使用sms指令
并且令opval={"phone":"17324139805","code":"356123","sms_sign":"群老大APP","order_number":"your-order-no","version":1}(其中phone参数为手机号码,code为验证码,sms_sign为短信签名--建议为公司名或者产品名(可选,不填写签名自动设置为“6DGS云”),version暂时只能为1,order_number为订单号非必填)
因为在浏览器里直接使用该参数,所以我们进行urlencode转码:
转码工具
转码得到opval:%7b%22phone%22%3a%2217324139805%22%2c%22code%22%3a%22356123%22%2c%22sms_sign%22%3a%22%e7%be%a4%e8%80%81%e5%a4%a7APP%22%2c%22order_number%22%3a%22your-order-no%22%2c%22version%22%3a1%7d
接口API的URL拼接如下:
https://c0.6dgs.opencom.cn/node.testphone.coin/op?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56&token_x=coin_0000000000000000&token_y=coin_6dgscloudsms0001&opcode=sms&opval=%7b%22phone%22%3a%2217324139805%22%2c%22code%22%3a%22356123%22%2c%22sms_sign%22%3a%22%e7%be%a4%e8%80%81%e5%a4%a7APP%22%2c%22order_number%22%3a%22your-order-no%22%2c%22version%22%3a1%7d&extra_data=sms-helloworld
得到的返回结果如下:
{"ret":true,"msg":"success","txid":"txid_31R5xnoUs44b9J2S","token_x":"coin_0000000000000000","token_y":"coin_6dgscloudsms0001","x_state":{"token_state_p":"[]","token_state_val":"20","token_height":14,"pre_txid":"txid_21EfrwpDyD5MfHVq","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"},"y_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":1,"public_key":"jACDVWxhmMf2vQbiUDJf2fZTJxveBFWiJzVSJCQDzhaK","token":"coin_6dgscloudsms0001"},"x6dgs_cloud_func_ret":{"ret":false,"msg":"account last sms-number is zero"}}
ret=true代表op接口调用和写入数据成功,这里判断短信是否发送成功是通过x6dgs_cloud_func_ret的回参数判断:
如这里所示:"x6dgs_cloud_func_ret":{"ret":false,"msg":"account last sms-number is zero"},意思是短信帐户为0,须先充值短信帐户
充值或者找客服沟通索取免费短信之后,可继续点击该发送短信API的URL,得到下述结果:
{"ret":true,"msg":"success","txid":"txid_271raEFYESTtnruw","token_x":"coin_0000000000000000","token_y":"coin_6dgscloudsms0001","x_state":{"token_state_p":"[]","token_state_val":"20","token_height":16,"pre_txid":"txid_21EfrwpDyD5MfHVq","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"},"y_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":2,"public_key":"jACDVWxhmMf2vQbiUDJf2fZTJxveBFWiJzVSJCQDzhaK","token":"coin_6dgscloudsms0001"},"x6dgs_cloud_func_ret":{"ret":true,"msg":"success","sms_last_num":"3999"}}
可以看到,"x6dgs_cloud_func_ret":{"ret":true,"msg":"success","sms_last_num":"3999"}代表已经发送短信成功,并且帐户余额3999条。
#2 使用模板发送验证码短信:
令opval={"phone":"17324139805","sms_sign":"群老大APP","template":"尊敬的用户:欢迎登录群老大APP,您的验证码为123456,有效期5分钟,请尽快完成登录","order_number":"your-order-no","version":1}(其中phone参数为手机号码,template为验证码的模板(包含了验证码),sms_sign为短信签名--建议为公司名或者产品名(可选,不填写签名自动设置为“6DGS云”),version暂时只能为1,order_number为订单号非必填)
转码得到opval:%7b%22phone%22%3a%2217324139805%22%2c%22sms_sign%22%3a%22%e7%be%a4%e8%80%81%e5%a4%a7APP%22%2c%22template%22%3a%22%e5%b0%8a%e6%95%ac%e7%9a%84%e7%94%a8%e6%88%b7%3a%e6%ac%a2%e8%bf%8e%e7%99%bb%e5%bd%95%e7%be%a4%e8%80%81%e5%a4%a7APP%2c%e6%82%a8%e7%9a%84%e9%aa%8c%e8%af%81%e7%a0%81%e4%b8%ba123456%2c%e6%9c%89%e6%95%88%e6%9c%9f5%e5%88%86%e9%92%9f%ef%bc%8c%e8%af%b7%e5%b0%bd%e5%bf%ab%e5%ae%8c%e6%88%90%e7%99%bb%e5%bd%95%22%2c%22order_number%22%3a%22your-order-no%22%2c%22version%22%3a1%7d
接口API的URL拼接如下:
https://c0.6dgs.opencom.cn/node.testphone.coin/op?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56&token_x=coin_0000000000000000&token_y=coin_6dgscloudsms0001&opcode=sms&opval=%7b%22phone%22%3a%2217324139805%22%2c%22sms_sign%22%3a%22%e7%be%a4%e8%80%81%e5%a4%a7APP%22%2c%22template%22%3a%22%e5%b0%8a%e6%95%ac%e7%9a%84%e7%94%a8%e6%88%b7%3a%e6%ac%a2%e8%bf%8e%e7%99%bb%e5%bd%95%e7%be%a4%e8%80%81%e5%a4%a7APP%2c%e6%82%a8%e7%9a%84%e9%aa%8c%e8%af%81%e7%a0%81%e4%b8%ba123456%2c%e6%9c%89%e6%95%88%e6%9c%9f5%e5%88%86%e9%92%9f%ef%bc%8c%e8%af%b7%e5%b0%bd%e5%bf%ab%e5%ae%8c%e6%88%90%e7%99%bb%e5%bd%95%22%2c%22order_number%22%3a%22your-order-no%22%2c%22version%22%3a1%7d&extra_data=sms-helloworld
得到的返回结果如下:
{"ret":true,"msg":"success","txid":"txid_24iPkGvScLwWYPkq","token_x":"coin_0000000000000000","token_y":"coin_6dgscloudsms0001","x_state":{"token_state_p":"[]","token_state_val":"30","token_height":76,"pre_txid":"txid_z4qz1uWSGJ8w4cG4","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"},"y_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":12,"public_key":"jACDVWxhmMf2vQbiUDJf2fZTJxveBFWiJzVSJCQDzhaK","token":"coin_6dgscloudsms0001"},"x6dgs_cloud_func_ret":{"ret":true,"msg":"success","sms_last_num":"3989"}}
【注意】使用短信模板,参数为template,不使用短信模板,则使用code参数(当template参数不为空且文本长度超过10个字符时,才会认为是有效的模板)。
通过6DGS云控制台的【短信帐户】管理,可以看到以下短信发送纪录:
当然,因为是op操作,也可通过/chain/opcode可以查询到op接口的每一条存储纪录点击查看/chain接口文档