瀏覽代碼

add sms.js

yangck 6 年之前
父節點
當前提交
8797d8a371
共有 1 個文件被更改,包括 68 次插入0 次删除
  1. 68 0
      lib/sms.js

+ 68 - 0
lib/sms.js

@@ -0,0 +1,68 @@
+var apis = require( './apis' );
+var rongrequest = require( './rongrequest' );
+
+exports.send = function( region, mobile, templateId, format, callback ) {
+	var params = {
+		region: region,
+		mobile: mobile,
+		templateId: templateId
+	};
+
+	callback = arguments[arguments.length - 1];
+
+	rongrequest.requestSMS( apis['sms']['send'], params, format, function( err, resultText ) {
+		return callback( err, resultText );
+	} );
+};
+
+exports.sendCode = function( region, mobile, verifyId, verifyCode, templateId, format, callback ) {
+	var params;
+
+	if (arguments.length > 5) {
+		params = {
+			region: region,
+			mobile: mobile,
+			verifyId: verifyId,
+			verifyCode: verifyCode,
+			templateId: templateId
+		};
+	} else {
+		templateId = verifyId;
+		format = verifyCode;
+
+		params = {
+			region: region,
+			mobile: mobile,
+			templateId: templateId
+		};
+	}
+
+	callback = arguments[arguments.length - 1];
+
+	rongrequest.requestSMS( apis['sms']['sendCode'], params, format, function( err, resultText ) {
+		return callback( err, resultText );
+	} );
+};
+
+exports.verifyCode = function( sessionId, code, format, callback ) {
+	var params = {
+		sessionId: sessionId,
+		code: code
+  };
+
+	callback = arguments[arguments.length - 1];
+
+	rongrequest.requestSMS( apis['sms']['verifyCode'], params, format, function( err, resultText ) {
+		return callback( err, resultText );
+	} );
+};
+
+exports.getImgCode = function( appKey, callback ) {
+	var params = {
+		appkey: appKey
+	}
+
+	rongrequest.get( apis['sms']['getImgCode'], params, function( err, resultText ) {
+		return callback( err, resultText );
+	} );
+};