sms.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var apis = require( './apis' );
  2. var rongrequest = require( './rongrequest' );
  3. exports.send = function( region, mobile, templateId, format, callback ) {
  4. var params = {
  5. region: region,
  6. mobile: mobile,
  7. templateId: templateId
  8. };
  9. callback = arguments[arguments.length - 1];
  10. rongrequest.requestSMS( apis['sms']['send'], params, format, function( err, resultText ) {
  11. return callback( err, resultText );
  12. } );
  13. };
  14. exports.sendCode = function( region, mobile, verifyId, verifyCode, templateId, format, callback ) {
  15. var params;
  16. if (arguments.length > 5) {
  17. params = {
  18. region: region,
  19. mobile: mobile,
  20. verifyId: verifyId,
  21. verifyCode: verifyCode,
  22. templateId: templateId
  23. };
  24. } else {
  25. templateId = verifyId;
  26. format = verifyCode;
  27. params = {
  28. region: region,
  29. mobile: mobile,
  30. templateId: templateId
  31. };
  32. }
  33. callback = arguments[arguments.length - 1];
  34. rongrequest.requestSMS( apis['sms']['sendCode'], params, format, function( err, resultText ) {
  35. return callback( err, resultText );
  36. } );
  37. };
  38. exports.verifyCode = function( sessionId, code, format, callback ) {
  39. var params = {
  40. sessionId: sessionId,
  41. code: code
  42. };
  43. callback = arguments[arguments.length - 1];
  44. rongrequest.requestSMS( apis['sms']['verifyCode'], params, format, function( err, resultText ) {
  45. return callback( err, resultText );
  46. } );
  47. };
  48. exports.getImgCode = function( appKey, callback ) {
  49. var params = {
  50. appkey: appKey
  51. }
  52. rongrequest.get( apis['sms']['getImgCode'], params, function( err, resultText ) {
  53. return callback( err, resultText );
  54. } );
  55. };