C # Write mobile and Unicom Interfaces

Source: Internet
Author: User
Tags sendmsg

  1. // Page call
  2. Private void SendMassage (string Telephone, string text)
  3. {
  4. SendMobile sm = new SendMobile (Telephone, text );
  5. Sm. SendMsg ();
  6. }
  7. // Reference
  8. Using System. Text;
  9. Using System. Net;
  10. Using System. IO;
  11. // Using cn. sh. unicom. groupsms;
  12. /// <Summary>
  13. /// Summary of SendMobile
  14. /// </Summary>
  15. Public class SendMobile
  16. {
  17. Public SendMobile ()
  18. {
  19. //
  20. // TODO: add the constructor logic here
  21. //
  22. }
  23. Private string _ MobNum;
  24. Private string _ MobMsg;
  25. Public SendMobile (string MobNum, string MobMsg)
  26. {
  27. This. _ MobNum = MobNum;
  28. This. _ MobMsg = MobMsg;
  29. }
  30. Public void SendMsg ()
  31. {
  32. If (CheckType (this. _ MobNum ))
  33. ToMobile ();
  34. Else
  35. ToUnicom ();
  36. }
  37. Public void ToMobile ()
  38. {// Mobile Interface
  39. Encoding encoding = Encoding. GetEncoding ("gb2312 ");
  40. String incluiseid = "123456"; // enterprise code
  41. String accountid = "15811150014"; // account
  42. String pwd = "630420"; // Password
  43. String postData = "enterpriseid =" enterpriseid "& accountid =" accountid "& pswd =" pwd "& mobs =" this. _ MobNum "& msg =" this. _ MobMsg;
  44. String strUrl = "http: // 211.136.163.68: 8000/httpserver ";
  45. Byte [] data = encoding. GetBytes (postData );
  46. // Prepare the request...
  47. HttpWebRequest myRequest = (HttpWebRequest) WebRequest. Create (strUrl );
  48. MyRequest. Method = "POST ";
  49. MyRequest. ContentType = "application/x-www-form-urlencoded ";
  50. MyRequest. ContentLength = data. Length;
  51. Stream newStream = myRequest. GetRequestStream ();
  52. // Send data
  53. NewStream. Write (data, 0, data. Length );
  54. NewStream. Close ();
  55. }
  56. Public void ToUnicom ()
  57. {// Unicom Interface
  58. Cn. sh. unicom. groupsms. Login myLogin = new cn. sh. unicom. groupsms. Login ();
  59. String MySessionID = "";
  60. MyLogin. username = "yourname"; // 123456789 username
  61. MyLogin. userType = "0 ";
  62. MyLogin. password = "yourpwd"; // password
  63. LoginMes mes1 = new LoginMes ();
  64. Mes1.login = myLogin;
  65. SmWSImplService Binding = new SmWSImplService ();
  66. OpResult Value1 = new OpResult ();
  67. Try
  68. {
  69. Value1 = Binding. memberLogin (mes1 );
  70. }
  71. Catch
  72. {
  73. }
  74. MySessionID = Value1.sessionId; // obtain the sessionid.
  75. SendBatchSMS (Binding, MySessionID, this. _ MobMsg, "companycode"); // companycode is the enterprise code 1112345
  76. Value1 = Binding. logout (mes1 );
  77. }
  78. Public bool CheckType (string MobileNum)
  79. {
  80. String ForeStr = MobileNum. Substring (0, 3 );
  81. Int ForeNum = Convert. ToInt32 (ForeStr );
  82. If (ForeNum <= 134)
  83. Return false;
  84. Else
  85. Return true;
  86. }
  87. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.