BondingUser.aspx.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. namespace LYFZ.WeixinServers.WeiXinAPP
  8. {
  9. public partial class BondingUser : System.Web.UI.Page
  10. {
  11. public string openid = "";
  12. public string cusid = "";
  13. public string appid = "";
  14. public string jsInfo = "";
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. if(!IsPostBack)
  18. {
  19. cusid = Request.QueryString["cusid"];
  20. openid = Request.QueryString["openid"];
  21. appid = Request.QueryString["appid"];
  22. }
  23. else
  24. {
  25. cusid = Request["cusid"];
  26. openid = Request["openid"];
  27. appid = Request["appid"];
  28. }
  29. }
  30. public void WriteLog(HttpContext context, string content, string filename = "")
  31. {
  32. if (string.IsNullOrEmpty(filename))
  33. {
  34. filename = DateTime.Now.ToString("yyyyMMddHHmmssffff");
  35. }
  36. string dirPath = context.Server.MapPath("/") + "/WeiXinDir/";
  37. if (!System.IO.Directory.Exists(dirPath))
  38. {
  39. System.IO.Directory.CreateDirectory(dirPath);
  40. }
  41. System.IO.File.AppendAllText(dirPath + "/" + filename + ".txt", content + "\r\n");
  42. }
  43. protected void Button1_Click(object sender, EventArgs e)
  44. {
  45. LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = Global.GetCustomerModelById(Request.Form["cusid"]);
  46. string openid = Request.Form["openid"];
  47. string account = Request.Form["mobilenumber"];
  48. string password = Request.Form["ordernumber"];
  49. string appid = Request.Form["appid"];
  50. string paramStr = "openid=" + openid + "&account=" + account + "&password=" + password + "&appid=" + appid;
  51. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(cusModel.GetRequestUrl()
  52. + "/api/WXApi.ashx/BindErpAccount?" + paramStr);
  53. if (getText != null)
  54. {
  55. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  56. if (jobject.GetValue("code").ToString().Equals("200"))
  57. {
  58. Response.Redirect("BindOK.html");
  59. }
  60. else
  61. {
  62. jsInfo = "<script>alert('" + jobject.GetValue("info").ToString() + "-" + jobject.GetValue("data").ToString() + "')</script>";
  63. }
  64. }
  65. else
  66. {
  67. jsInfo = "<script>alert('绑定反馈返回未空,可能无法和客户服务器通讯" + cusModel.GetRequestUrl() + "通讯引起的!')</script>";
  68. }
  69. WriteLog(HttpContext.Current, getText);
  70. }
  71. }
  72. }