frmAccountInformation.cs 16 KB

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