qcloudsms / qcloudsms_csharp

qcloudsms C# SDK
MIT License
24 stars 6 forks source link

This API is so terrible #4

Closed microestc closed 5 years ago

microestc commented 5 years ago

URL 示例 POST https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=xxxxx&random=xxxx

注:sdkappid 请填写您在腾讯云上申请到的,random 请填成随机数。

请求参数 { "ext": "", "extend": "", "params": [ "验证码", "1234", "4" ], "sig": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4", "sign": "腾讯云", "tel": { "mobile": "13788888888", "nationcode": "86" }, "time": 1457336869, "tpl_id": 19 }

microestc commented 5 years ago

Task SendAsync(string destination, string message) This API tells me how to pass parameters, how to extend, and I have to write a method separately. Why do I use template ID and then pass variables? Too much trouble

microestc commented 5 years ago

public SmsSingleSenderResult send(int type, string nationCode, string phoneNumber, string msg, string extend, string ext) { long random = SmsSenderUtil.getRandom(); long now = SmsSenderUtil.getCurrentTime(); JSONObjectBuilder body = new JSONObjectBuilder() .Put("tel", (new JSONObjectBuilder()).Put("nationcode", nationCode).Put("mobile", phoneNumber).Build()) .Put("type", type) .Put("msg", msg) .Put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber)) .Put("time", now) .Put("extend", !String.IsNullOrEmpty(extend) ? extend : "") .Put("ext", !String.IsNullOrEmpty(ext) ? ext : "");

        HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
            .addHeader("Conetent-Type", "application/json")
            .addQueryParameter("sdkappid", this.appid)
            .addQueryParameter("random", random)
            .setConnectionTimeout(60 * 1000)
            .setRequestTimeout(60 * 1000)
            .setBody(body.Build().ToString());

        // May throw HttpRequestException
        HTTPResponse res = httpclient.fetch(req);

        // May throw HTTPException
        handleError(res);

        SmsSingleSenderResult result = new SmsSingleSenderResult();
        // May throw JSONException
        result.parseFromHTTPResponse(res);

        return result;
    }

what's msg and type mean, the API is not explained This method, if available, should meet my needs

qcloudsms commented 5 years ago

For full documentation please see sdk doc https://qcloudsms.github.io/qcloudsms_csharp/index.html