frmAccountInformation.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace LYFZ.WeinaSmsInterface
  11. {
  12. public partial class frmAccountInformation : LYFZ.ComponentLibrary.BaseContentsFormMain
  13. {
  14. public frmAccountInformation()
  15. {
  16. InitializeComponent();
  17. this.Shown += frmAccountInformation_Shown;
  18. this.chkOpen.Click += chkOpen_Click;
  19. }
  20. void chkOpen_Click(object sender, EventArgs e)
  21. {
  22. if (this.rdobtnSingleShot.Checked)
  23. {
  24. this.CurrentSMSAccountInformation.IsSingleOpen = this.chkOpen.Checked;
  25. }
  26. else
  27. {
  28. this.CurrentSMSAccountInformation.IsBulkOpen = this.chkOpen.Checked;
  29. }
  30. }
  31. /* string _Account = "";
  32. /// <summary>
  33. /// 帐号
  34. /// </summary>
  35. public string Account
  36. {
  37. get { return _Account; }
  38. set { _Account = value; }
  39. }
  40. string _Password = "";
  41. /// <summary>
  42. /// 密码
  43. /// </summary>
  44. public string Password
  45. {
  46. get { return _Password; }
  47. set { _Password = value; }
  48. }*/
  49. /// <summary>
  50. /// 帐号
  51. /// </summary>
  52. string Account = "";
  53. /// <summary>
  54. /// 密码
  55. /// </summary>
  56. string Password = "";
  57. /// <summary>
  58. /// 旧的帐号信息
  59. /// </summary>
  60. string oldAccountInfo = "";
  61. public frmAccountInformation(LYFZ.Model.Model_SMSAccountInformation sMSAccountInformation)
  62. :this()
  63. {
  64. this.currentSMSAccountInformation = sMSAccountInformation;
  65. this.skinTextBoxAccount.Text = sMSAccountInformation.SingleUid; ;
  66. this.skinTextBoxPassword.Text = sMSAccountInformation.SinglePwd;
  67. this.skinTextBox1.Text = sMSAccountInformation.SingleRechargeRemindbalance.ToString();// _rechargeRemindbalance.ToString();
  68. this.skinTextBox2.Text = sMSAccountInformation.SingleRechargeRemindPhone;// _rechargeRemindPhone;
  69. this.chkOpen.Checked = sMSAccountInformation.IsSingleOpen;
  70. this.nudCount.Value = sMSAccountInformation.SwitchingCondition;
  71. this.Account = this.skinTextBoxAccount.Text;
  72. this.Password = this.skinTextBoxPassword.Text;
  73. this.oldAccountInfo = sMSAccountInformation.SingleUid
  74. + sMSAccountInformation.SinglePwd
  75. + sMSAccountInformation.SwitchingCondition
  76. + sMSAccountInformation.SingleServiceNumber
  77. + sMSAccountInformation.SingleRechargeRemindbalance.ToString()
  78. + sMSAccountInformation.SingleRechargeRemindPhone
  79. + sMSAccountInformation.BulkUid
  80. + sMSAccountInformation.BulkPwd
  81. + sMSAccountInformation.BulkServiceNumber
  82. + sMSAccountInformation.BulkRechargeRemindbalance.ToString()
  83. + this.currentSMSAccountInformation.IsSingleOpen.ToString()
  84. + this.currentSMSAccountInformation.IsBulkOpen.ToString()
  85. + sMSAccountInformation.BulkRechargeRemindPhone;
  86. }
  87. /// <summary>
  88. /// 是否有更新帐号
  89. /// </summary>
  90. public bool GetIsUpdateAccount()
  91. {
  92. if (this.oldAccountInfo != (this.currentSMSAccountInformation.SingleUid
  93. + this.currentSMSAccountInformation.SinglePwd
  94. + this.currentSMSAccountInformation.SwitchingCondition
  95. + this.currentSMSAccountInformation.SingleServiceNumber
  96. + this.currentSMSAccountInformation.SingleRechargeRemindbalance.ToString()
  97. + this.currentSMSAccountInformation.SingleRechargeRemindPhone
  98. + this.currentSMSAccountInformation.BulkUid
  99. + this.currentSMSAccountInformation.BulkPwd
  100. + this.currentSMSAccountInformation.BulkServiceNumber
  101. + this.currentSMSAccountInformation.BulkRechargeRemindbalance.ToString()
  102. + this.currentSMSAccountInformation.IsSingleOpen.ToString()
  103. + this.currentSMSAccountInformation.IsBulkOpen.ToString()
  104. + this.currentSMSAccountInformation.BulkRechargeRemindPhone))
  105. {
  106. return true;
  107. }
  108. else
  109. {
  110. return false;
  111. }
  112. }
  113. LYFZ.Model.Model_SMSAccountInformation currentSMSAccountInformation = new Model.Model_SMSAccountInformation();
  114. /// <summary>
  115. /// 短信接口帐号信息
  116. /// </summary>
  117. public LYFZ.Model.Model_SMSAccountInformation CurrentSMSAccountInformation
  118. {
  119. get { return currentSMSAccountInformation; }
  120. set { currentSMSAccountInformation = value; }
  121. }
  122. //创建一个委托,是为访问控件服务的。
  123. public delegate void UpdateControls();
  124. void frmAccountInformation_Shown(object sender, EventArgs e)
  125. {
  126. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  127. {
  128. try
  129. {
  130. SmsUserInfo userinfo =new SmsUserInfo(HTTPSmsInterface.GetBalances(this.Account, this.Password));
  131. this.Invoke(new UpdateControls(delegate()
  132. {
  133. lab查询结果.Text = "查询" + userinfo.ReturnStatus;
  134. lb用户名.Text = this.Account;
  135. lb余额.Text = userinfo.Balance;
  136. // lb单价.Text = userinfo.Price.ToString();
  137. // lb短信字符数.Text = userinfo.SMSCharacterCount.ToString();
  138. lb短信签名.Text = userinfo.Signatures;
  139. if (userinfo.Signatures.Trim() == "未设置签名")
  140. {
  141. lb短信签名.Text = userinfo.Username;
  142. }
  143. // lb语音单价.Text = userinfo.VoiceMessagingPrice.ToString();
  144. // lb彩信单价.Text = userinfo.MMSPrice.ToString();
  145. // lb传真单价.Text = userinfo.FaxMessagingPrice.ToString();
  146. }));
  147. }
  148. catch (Exception ex)
  149. {
  150. this.Invoke(new UpdateControls(delegate()
  151. {
  152. lab查询结果.Text = "帐号余额查询失败";
  153. }));
  154. MessageBoxCustom.Show("帐号余额查询失败," + ex.Message, backgroundWorker: backgroundWorker);
  155. }
  156. });
  157. }
  158. private void skinButtomQuery_Click(object sender, EventArgs e)
  159. {
  160. this.Account = this.skinTextBoxAccount.Text;
  161. this.Password = this.skinTextBoxPassword.Text;
  162. this.CurrentSMSAccountInformation.SwitchingCondition = Convert.ToInt32(this.nudCount.Value);
  163. if (this.rdobtnSingleShot.Checked)
  164. {
  165. this.CurrentSMSAccountInformation.SingleUid = this.skinTextBoxAccount.Text.Trim();
  166. this.CurrentSMSAccountInformation.SinglePwd = this.skinTextBoxPassword.Text.Trim();
  167. //this.CurrentSMSAccountInformation.SingleRechargeRemindbalance = Convert.ToInt32(this.skinTextBox1.Text.Trim());
  168. //this.CurrentSMSAccountInformation.SingleRechargeRemindPhone = this.skinTextBox2.Text.Trim();
  169. }
  170. else
  171. {
  172. this.CurrentSMSAccountInformation.BulkUid = this.skinTextBoxAccount.Text.Trim();
  173. this.CurrentSMSAccountInformation.BulkPwd = this.skinTextBoxPassword.Text.Trim();
  174. //this.CurrentSMSAccountInformation.BulkRechargeRemindbalance = Convert.ToInt32(this.skinTextBox1.Text.Trim());
  175. //this.CurrentSMSAccountInformation.BulkRechargeRemindPhone = this.skinTextBox2.Text.Trim();
  176. }
  177. frmAccountInformation_Shown(null, null);
  178. }
  179. private void skinButtomSendSms_Click(object sender, EventArgs e)
  180. {
  181. this.Account = this.skinTextBoxAccount.Text.Trim();
  182. this.Password = this.skinTextBoxPassword.Text.Trim();
  183. string RecipientPhone = this.skinTextBoxPhoneNumber.Text.Trim();
  184. string SMSContent = this.skinTextBoxSmsInfo.Text.Trim();
  185. string ErrorPhone = LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(RecipientPhone, ref RecipientPhone);
  186. if (ErrorPhone.Length > 0)
  187. {
  188. MessageBoxCustom.Show("请求发送手机号格式不正确,以下为错误手机号:\r\n" + ErrorPhone);
  189. return;
  190. }
  191. string[] phones = RecipientPhone.Split(',');
  192. if (phones.Length > 100)
  193. {
  194. MessageBoxCustom.Show("请求发送手机号过多,一次只能同时发送给100个手机号,当前请求手机号个数:" + phones.Length);
  195. return;
  196. }
  197. if (SMSContent.Length > 300)
  198. {
  199. MessageBoxCustom.Show("请求发送短信长度为:" + SMSContent.Length + "个字符,测试发送短信内容超长,不能发送。");
  200. return;
  201. }
  202. if (SMSContent.Length <= 0)
  203. {
  204. MessageBoxCustom.Show("短信内容不能为空。");
  205. return;
  206. }
  207. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  208. {
  209. try
  210. {
  211. HTTPSmsSendReturnInfo sendInfo = HTTPSmsInterface.SendSmsMessages(this.Account, this.Password, RecipientPhone, SMSContent);
  212. try
  213. {
  214. if (sendInfo.ReturnStatus.Contains("成功"))
  215. {
  216. LYFZ.DAL.tb_SMSSendRecords smsDal = new DAL.tb_SMSSendRecords();
  217. LYFZ.Model.tb_SMSSendRecords smsModel = new Model.tb_SMSSendRecords();
  218. smsModel.SMSAccount = this.Account;
  219. smsModel.CustomerID = smsDal.GetSendRecordID(this.Account);
  220. smsModel.RecipientPhone = sendInfo.SendSuccessTel;
  221. smsModel.SMSContent = SMSContent;
  222. smsModel.Status = SendSmsResults.SendStatus.发送成功.ToString();
  223. smsModel.SMSCustomerDateTime = DateTime.Now;
  224. smsModel.RecipientDateTime = DateTime.Now;
  225. smsModel.SendDateTime = DateTime.Now;
  226. smsModel.AgentChargeback = sendInfo.SendCount;
  227. smsModel.OperatorChargeback = sendInfo.SendCount;
  228. smsModel.AgentPrice = sendInfo.Price;
  229. smsModel.OperatorPrice = smsModel.AgentPrice;
  230. smsModel.SendLogs = sendInfo.SourceString;
  231. smsModel.SendFailureNumber = 0;
  232. smsModel.PartialFailurePhone = sendInfo.SendFaileTel;
  233. smsModel.WaitingToSend = "";
  234. smsModel.SMSInterface = "北京维那公司";
  235. smsModel.CustomerQueries = "1";
  236. string md5Key = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(smsModel.RecipientPhone + smsModel.SMSContent + smsModel.SMSCustomerDateTime);
  237. smsModel.MD5KEY = md5Key;
  238. smsDal.Add(smsModel);
  239. }
  240. }
  241. catch { sendInfo.ReturnStatus = "发送成功,但记录插入错误"; }
  242. this.Invoke(new UpdateControls(delegate()
  243. {
  244. this.labelEx发送结果.Text = sendInfo.ReturnStatus + "\r\n" + sendInfo.SourceString;
  245. }));
  246. }
  247. catch (Exception ex)
  248. {
  249. MessageBoxCustom.Show("发送错误," + ex.Message, backgroundWorker: backgroundWorker);
  250. }
  251. });
  252. }
  253. /* int rechargeRemindbalance = 200;
  254. /// <summary>
  255. /// 充值提醒余额
  256. /// </summary>
  257. public int RechargeRemindbalance
  258. {
  259. get { return rechargeRemindbalance; }
  260. set { rechargeRemindbalance = value; }
  261. }
  262. string rechargeRemindPhone = "";
  263. /// <summary>
  264. /// 充值提醒短信接收手机号
  265. /// </summary>
  266. public string RechargeRemindPhone
  267. {
  268. get { return rechargeRemindPhone; }
  269. set { rechargeRemindPhone = value; }
  270. }*/
  271. private void skinButtom1_Click(object sender, EventArgs e)
  272. {
  273. try
  274. {
  275. //this.CurrentSMSAccountInformation.SingleRechargeRemindbalance =Convert.ToInt32(this.skinTextBox1.Text.Trim());
  276. // this.CurrentSMSAccountInformation.SingleRechargeRemindPhone = this.skinTextBox2.Text.Trim();
  277. this.CurrentSMSAccountInformation.SwitchingCondition = Convert.ToInt32(this.nudCount.Value);
  278. if (this.rdobtnSingleShot.Checked)
  279. {
  280. this.CurrentSMSAccountInformation.SingleRechargeRemindbalance = Convert.ToInt32(this.skinTextBox1.Text.Trim());
  281. this.CurrentSMSAccountInformation.SingleRechargeRemindPhone = this.skinTextBox2.Text.Trim();
  282. }
  283. else
  284. {
  285. this.CurrentSMSAccountInformation.BulkRechargeRemindbalance = Convert.ToInt32(this.skinTextBox1.Text.Trim());
  286. this.CurrentSMSAccountInformation.BulkRechargeRemindPhone = this.skinTextBox2.Text.Trim();
  287. }
  288. MessageBoxCustom.Show("保存成功");
  289. }
  290. catch
  291. {
  292. MessageBoxCustom.Show("输入信息不正确");
  293. }
  294. }
  295. /// <summary>
  296. /// 单发通道
  297. /// </summary>
  298. /// <param name="sender"></param>
  299. /// <param name="e"></param>
  300. private void rdobtnSingleShot_Click(object sender, EventArgs e)
  301. {
  302. this.skinTextBoxAccount.Text = this.CurrentSMSAccountInformation.SingleUid;
  303. this.skinTextBoxPassword.Text = this.CurrentSMSAccountInformation.SinglePwd;
  304. this.skinTextBox1.Text = this.CurrentSMSAccountInformation.SingleRechargeRemindbalance.ToString();
  305. this.skinTextBox2.Text = this.CurrentSMSAccountInformation.SingleRechargeRemindPhone;
  306. this.chkOpen.Checked = this.CurrentSMSAccountInformation.IsSingleOpen;
  307. skinButtomQuery_Click(sender, e);
  308. }
  309. /// <summary>
  310. /// 群发通单
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void rdobtnBulk_Click(object sender, EventArgs e)
  315. {
  316. this.skinTextBoxAccount.Text = this.CurrentSMSAccountInformation.BulkUid;
  317. this.skinTextBoxPassword.Text = this.CurrentSMSAccountInformation.BulkPwd;
  318. this.skinTextBox1.Text = this.CurrentSMSAccountInformation.BulkRechargeRemindbalance.ToString();
  319. this.skinTextBox2.Text = this.CurrentSMSAccountInformation.BulkRechargeRemindPhone;
  320. this.chkOpen.Checked = this.CurrentSMSAccountInformation.IsBulkOpen;
  321. skinButtomQuery_Click(sender, e);
  322. }
  323. }
  324. }