1805 lines
83 KiB
C#
1805 lines
83 KiB
C#
using Aliyun.Acs.Core;
|
||
using Aliyun.Acs.Core.Exceptions;
|
||
using Aliyun.Acs.Core.Profile;
|
||
using Aliyun.Acs.Dysmsapi.Model.V20170525;
|
||
using Apache.NMS;
|
||
using Apache.NMS.ActiveMQ;
|
||
using dccdc.BLL;
|
||
using dccdc.Common;
|
||
using dccdc.Models;
|
||
using dccdc.Models.WeiXin;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Reflection;
|
||
using System.Security.Cryptography;
|
||
using System.Security.Cryptography.X509Certificates;
|
||
using System.Text;
|
||
using System.Web;
|
||
using System.Web.Mvc;
|
||
using System.Xml;
|
||
using WxPayAPI;
|
||
|
||
namespace dccdc.Controllers
|
||
{
|
||
public class InfectionWXController : Controller
|
||
{
|
||
[AllowAnonymous]
|
||
// GET: WeiXin
|
||
[HttpGet]
|
||
public string Index()
|
||
{
|
||
string echostr = Request.QueryString["echostr"];
|
||
return CheckSignature() ? echostr : "error";
|
||
}
|
||
|
||
|
||
[AllowAnonymous]
|
||
[HttpPost]
|
||
public string Index(FormCollection fc)
|
||
{
|
||
string postString;
|
||
using (Stream stream = Request.InputStream)
|
||
{
|
||
Byte[] postBytes = new Byte[stream.Length];
|
||
stream.Read(postBytes, 0, (Int32)stream.Length);
|
||
postString = Encoding.UTF8.GetString(postBytes);
|
||
}
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(postString);
|
||
string signature = Request.QueryString["signature"];
|
||
string timestamp = Request.QueryString["timestamp"];
|
||
string nonce = Request.QueryString["nonce"];
|
||
string msg_signature = Request.QueryString["msg_signature"];
|
||
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(signature);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(timestamp);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(nonce);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(msg_signature);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(postString);
|
||
|
||
//if (CheckSignature())
|
||
//{
|
||
// log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("成功!");
|
||
|
||
//}
|
||
WXBizMsgCrypt wxbiz = new WXBizMsgCrypt(Common.Global.InfectionToken, Common.Global.InfectionEncodingAESKey, Common.Global.InfectionAppId);
|
||
string msg = postString;
|
||
int code = wxbiz.DecryptMsg(msg_signature, timestamp, nonce, postString, ref msg);
|
||
//msg = postString;
|
||
//int code = 0;
|
||
string retmsg = string.Empty;
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(msg);
|
||
try
|
||
{
|
||
XmlDocument doc = new XmlDocument();
|
||
doc.LoadXml(msg);
|
||
XmlNode root = doc.FirstChild;
|
||
var xmlElement = root["MsgType"];
|
||
if (xmlElement != null)
|
||
{
|
||
string msgType = xmlElement.InnerText;
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(msgType);
|
||
|
||
switch (msgType.ToLower())
|
||
{
|
||
case "event":
|
||
retmsg = ExecEvent(doc);
|
||
break;
|
||
case "text":
|
||
retmsg = ExecText(doc);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(ex.Message);
|
||
|
||
}
|
||
if (string.IsNullOrEmpty(retmsg))
|
||
return retmsg;
|
||
else
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(retmsg);
|
||
|
||
int t_code = wxbiz.EncryptMsg(retmsg, timestamp, nonce, ref msg);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(msg);
|
||
if (t_code == 0)
|
||
return msg;
|
||
else
|
||
{
|
||
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(t_code.ToString());
|
||
return "";
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|
||
private string ExecEvent(XmlDocument doc)
|
||
{
|
||
string msg = string.Empty;
|
||
XmlNode root = doc.FirstChild;
|
||
var xmlElement = root["Event"];
|
||
if (xmlElement != null)
|
||
{
|
||
var Event = xmlElement.InnerText;
|
||
var element = root["FromUserName"];
|
||
if (element != null)
|
||
{
|
||
string openid = element.InnerText;
|
||
string scene = root["EventKey"] == null ? "" : root["EventKey"].InnerText.Replace("qrscene_", "");
|
||
switch (Event)
|
||
{
|
||
case "subscribe":
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("关注微信");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("openid:" + openid);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("appid:" + Global.InfectionAppId);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("Appsecret:" + Global.InfectionAppsecret);
|
||
InfectionOpenUserModel ou = getopenuser(openid);
|
||
ou.remark = scene;
|
||
ou.recommendold = RecommendNumber();
|
||
//推荐码已存在
|
||
while (new BLL.InfectionOpenUserInfoBll().JudgementCode(ou.recommendold) == "True")
|
||
{
|
||
ou.recommendold = RecommendNumber();
|
||
}
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("openuser:" + Newtonsoft.Json.JsonConvert.SerializeObject(ou));
|
||
try
|
||
{
|
||
new BLL.InfectionOpenUserBll().updateOpenUserInfection(ou);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(ex.Message);
|
||
}
|
||
|
||
var data = new
|
||
{
|
||
touser = openid,
|
||
template_id = "x8mjZxVpKoOg8TiYVevRcDjKxBYjFqAHi7PRIetidp8",
|
||
url = "http://oa.dcqcdc.com/dccdc/Infection/personInfoEntering",
|
||
data = new
|
||
{
|
||
first = new { value = "您好,为了更好与您交流,请完善您的个人信息", color = "#173177" },
|
||
keyword1 = new { value = "个人信息", color = "#173177" },
|
||
keyword2 = new { value = "德城健康e路", color = "#173177" },
|
||
//keyword3 = new { value = model.ADate.ToString("yyyy-MM-dd"), color = "#173177" },
|
||
remark = new { value = "点击完善个人信息。", color = "#173177" },
|
||
}
|
||
};
|
||
|
||
WebClient wc = new WebClient();
|
||
wc.UploadData("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + Common.Global.getAccessTokenInfection.access_token, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(data)));
|
||
|
||
var comm = new BLL.Common();
|
||
string xiaoxi = @"
|
||
<ArticleCount>1</ArticleCount><Articles><item>
|
||
<Title><![CDATA[HI " + ou.nickname + @"~" + comm.getParm_Value("wxafgztitleym", "欢迎关注健康E路微信公众号,您的专享健康管家", "微信关注消息标题(疫苗)") + @"]]></Title>
|
||
<Description><![CDATA[" + comm.getParm_Value("wxafgzjjym", "详情请点击了解", "微信关注消息简介(疫苗)") + @"]]></Description>
|
||
<PicUrl><![CDATA[" + "http://oa.dcqcdc.com/dccdc/Images/follow.png" + @"]]></PicUrl>
|
||
<Url><![CDATA[" + "http://oa.dcqcdc.com/dccdc/Infection/Follow" + @"]]></Url>
|
||
</item></Articles>";
|
||
//string xiaoxi = @"<Content><![CDATA[HI " + ou.nickname + @"~" + comm.getParm_Value("wxgztitleym", "欢迎关注德城健康e路微信公众号", "微信关注消息标题(疫苗)") + @"]]></Content>";
|
||
msg = CreateNews(openid, "news", xiaoxi);
|
||
break;
|
||
case "unsubscribe":
|
||
// var opuunsubscribe = cont.OpenUser.Find(new[] { openid });
|
||
//ou = getopenuser(openid);
|
||
//updateOpenUser(ou);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("取消关注");
|
||
//unsubscribe(openid);
|
||
break;
|
||
case "SCAN":
|
||
new BLL.InfectionOpenUserBll().updateRemarkInfection(openid, scene);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return msg;
|
||
}
|
||
|
||
private string ExecText(XmlDocument doc)
|
||
{
|
||
string msg = string.Empty;
|
||
XmlNode root = doc.FirstChild;
|
||
var element = root["FromUserName"];
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(element);
|
||
if (element != null)
|
||
{
|
||
string openid = element.InnerText;
|
||
msg = CreateKF(openid, "transfer_customer_service");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(msg);
|
||
}
|
||
return msg;
|
||
}
|
||
|
||
#region 校验开发者
|
||
private bool CheckSignature()
|
||
{
|
||
string signature = Request.QueryString["signature"];
|
||
string timestamp = Request.QueryString["timestamp"];
|
||
string nonce = Request.QueryString["nonce"];
|
||
string[] arrTmp = { Common.Global.InfectionToken, timestamp, nonce };
|
||
//string[] arrTmp = { Token, timestamp, nonce };
|
||
Array.Sort(arrTmp);//字典排序
|
||
string tmpStr = string.Join("", arrTmp);
|
||
var sha1 = System.Security.Cryptography.SHA1.Create();
|
||
tmpStr = BitConverter.ToString(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(tmpStr))).Replace("-", ""); //对该字符串进行sha1加密
|
||
tmpStr = tmpStr.ToLower();//对字符串中的字母部分进行小写转换,非字母字符不作处理
|
||
//WriteLog(tmpStr);//计入日志
|
||
if (tmpStr == signature)//开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。开发者通过检验signature对请求进行校验,若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,否则接入失败
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
#region 获取微信信息
|
||
/// <summary>
|
||
/// 读取微信用户信息
|
||
/// </summary>
|
||
/// <param name="openid"></param>
|
||
/// <returns></returns>
|
||
private InfectionOpenUserModel getopenuser(string openid)
|
||
{
|
||
var accessToken = Common.Global.getAccessTokenInfection;
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("accessToken:" + Newtonsoft.Json.JsonConvert.SerializeObject(accessToken));
|
||
WebClient wc = new WebClient();
|
||
var stream = wc.OpenRead("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + accessToken.access_token + "&openid=" + openid + "&lang=zh_CN");
|
||
var sr = new StreamReader(stream);
|
||
string token = sr.ReadToEnd();
|
||
sr.Close();
|
||
stream.Dispose();
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(token);
|
||
var ou = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.InfectionOpenUserModel>(token);
|
||
if (string.IsNullOrEmpty(ou.openid))
|
||
{
|
||
error err = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.WeiXin.error>(token);
|
||
Exception wx = new Exception(err.errmsg + "\r\n" + err.errcode);
|
||
throw wx;
|
||
}
|
||
|
||
return ou;
|
||
}
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 生成返回消息
|
||
/// </summary>
|
||
/// <param name="touser"></param>
|
||
/// <param name="type"></param>
|
||
/// <param name="xiaoxi"></param>
|
||
/// <returns></returns>
|
||
string CreateNews(string touser, string type, string xiaoxi)
|
||
{
|
||
string msg = @"<xml><ToUserName><![CDATA[" + touser + @"]]></ToUserName><FromUserName><![CDATA[" + Common.Global.InfectionMyId + @"]]></FromUserName><CreateTime>" + GetNowTime() + @"</CreateTime><MsgType><![CDATA[" + type + @"]]></MsgType>" + xiaoxi + @"</xml> ";
|
||
return msg;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成返回消息
|
||
/// </summary>
|
||
/// <param name="touser"></param>
|
||
/// <param name="type"></param>
|
||
/// <param name="xiaoxi"></param>
|
||
/// <returns></returns>
|
||
string CreateKF(string touser, string type)
|
||
{
|
||
string msg = @"<xml><ToUserName><![CDATA[" + touser + @"]]></ToUserName><FromUserName><![CDATA[" + Common.Global.InfectionMyId + @"]]></FromUserName><CreateTime>" + GetNowTime() + @"</CreateTime><MsgType><![CDATA[" + type + @"]]></MsgType></xml> ";
|
||
return msg;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取时间差
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
int GetNowTime()
|
||
{
|
||
return (int)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalSeconds;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过时间差获取时间
|
||
/// </summary>
|
||
/// <param name="tick"></param>
|
||
/// <returns></returns>
|
||
DateTime getTime(int tick)
|
||
{
|
||
return TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)).AddSeconds(tick);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 关注用户页面
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public ActionResult OpenUserList()
|
||
{
|
||
List<ERPUser> erpList = new ERPUserBll().GetSelectList();
|
||
List<SelectListItem> itemList = new List<SelectListItem>();
|
||
foreach (ERPUser user in erpList)
|
||
{
|
||
SelectListItem item = new SelectListItem()
|
||
{
|
||
Value = user.ID.ToString(),
|
||
Text = user.TrueName.ToString()
|
||
};
|
||
itemList.Add(item);
|
||
}
|
||
SelectList select = new SelectList(itemList, "Value", "Text");
|
||
|
||
ViewBag.OAList = select;
|
||
return View();
|
||
}
|
||
/// <summary>
|
||
/// 获取关注用户列表
|
||
/// </summary>
|
||
/// <param name="nc"></param>
|
||
/// <param name="bz"></param>
|
||
/// <param name="page"></param>
|
||
/// <param name="pagesize"></param>
|
||
/// <returns></returns>
|
||
public JsonResult getOpenUserList(string nc, string bz, int page, int pagesize)
|
||
{
|
||
InfectionOpenUserBll bll = new InfectionOpenUserBll();
|
||
ERPUserBll ErpBll = new ERPUserBll();
|
||
int count = bll.getGZCountInfection(nc, bz);
|
||
List<InfectionOpenUserModel> list = bll.getGZListInfection(nc, bz, page, pagesize);
|
||
for(int i = 0; i < list.Count; i++)
|
||
{
|
||
string trueName = ErpBll.GetTrueNameById(list[i].oa_id);
|
||
list[i].oa_trueName = trueName;
|
||
}
|
||
|
||
return Json(new { Total = count, Rows = list });
|
||
}
|
||
/// <summary>
|
||
/// 备注关注用户
|
||
/// </summary>
|
||
/// <param name="openid"></param>
|
||
/// <param name="bz"></param>
|
||
/// <returns></returns>
|
||
public JsonResult remark(string openid, string bz)
|
||
{
|
||
try
|
||
{
|
||
var bll = new InfectionOpenUserBll();
|
||
var c = bll.remarkGZInfection(openid, bz);
|
||
if (c > 0)
|
||
{
|
||
/*
|
||
* {
|
||
"openid":"oDF3iY9ffA-hqb2vVvbr7qxf6A0Q",
|
||
"remark":"pangzi"
|
||
}
|
||
*/
|
||
var data = new { openid = openid, remark = bz };
|
||
WebClient wc = new WebClient();
|
||
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
||
log4net.LogManager.GetLogger(this.GetType()).Info(Newtonsoft.Json.JsonConvert.SerializeObject(data));
|
||
var result = wc.UploadData("https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=" + Common.Global.getAccessTokenInfection.access_token, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(data)));
|
||
string jg = System.Text.Encoding.UTF8.GetString(result);
|
||
var rjg = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.WeiXin.error>(jg);
|
||
if (rjg.errmsg == "ok")
|
||
{
|
||
return Json(new { State = 1, Message = "修改成功!" });
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = jg });
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = "没有数据备注成功!" });
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Json(new { State = 0, Message = ex.Message });
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 备注关注用户
|
||
/// </summary>
|
||
/// <param name="openid"></param>
|
||
/// <param name="bz"></param>
|
||
/// <returns></returns>
|
||
public JsonResult userState(string id, string type ,string oaId)
|
||
{
|
||
try
|
||
{
|
||
var bll = new InfectionOpenUserBll();
|
||
if (string.IsNullOrEmpty(oaId))
|
||
{
|
||
oaId = "0";
|
||
}
|
||
int i = bll.updateAdminById(id, type, oaId);
|
||
if (i>0)
|
||
{
|
||
return Json(new { State = 1, Message = "修改成功!" });
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = "修改失败!" });
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Json(new { State = 0, Message = ex.Message });
|
||
}
|
||
}
|
||
|
||
//添加用户信息页面
|
||
public ActionResult addOpenUserInfoQuery(string id)
|
||
{
|
||
InfectionOpenUserInfoModel model = new InfectionOpenUserInfoModel();
|
||
if (id != null && id != "") {
|
||
model.user_id = int.Parse(id);
|
||
}
|
||
ViewBag.user_id = model.user_id;
|
||
ViewBag.src = model.license;
|
||
List<InfectionOpenCrowdModel> list = new InfectionOpenCrowdBll().GetOpenDataList();
|
||
List<SelectListItem> itemList = new List<SelectListItem>();
|
||
foreach (InfectionOpenCrowdModel crowd in list)
|
||
{
|
||
SelectListItem item = new SelectListItem()
|
||
{
|
||
Value = crowd.id.ToString(),
|
||
Text = crowd.name.ToString()
|
||
};
|
||
itemList.Add(item);
|
||
}
|
||
SelectList select = new SelectList(itemList, "Value", "Text");
|
||
|
||
ViewBag.crowdList = select;
|
||
return View(model);
|
||
}
|
||
//保存用户信息
|
||
[HttpPost]
|
||
public string addOpenUserInfoQuerySave(InfectionOpenUserInfoModel model)
|
||
{
|
||
InfectionOpenUserInfoBll bll = new InfectionOpenUserInfoBll();
|
||
if (Request.Files.Count == 0)
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "没有要处理的文件" });
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
string path = string.Empty;
|
||
string address = string.Empty;
|
||
path = Server.MapPath("~/photo/");
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
string specificDate = DateTime.Now.ToString("yyyyMMdd").ToString();
|
||
path += specificDate + "/";
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
address = DateTime.Now.ToString("HHmmss") + "-" + Guid.NewGuid().ToString() + ".jpg";
|
||
path += address;
|
||
Request.Files[0].SaveAs(path);
|
||
address = "/photo/" + specificDate + "/" + address;
|
||
|
||
model.license = address;
|
||
DateTime date = new DateTime();
|
||
date = DateTime.Now;
|
||
model.create_time = date.ToString("yyyy-MM-dd hh:mm:ss");
|
||
bll.Add(model);
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = "保存成功!" });
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
|
||
}
|
||
}
|
||
//DateTime date = new DateTime();
|
||
//date = DateTime.Now;
|
||
//model.create_time = date.ToString("yyyy-MM-dd hh:mm:ss");
|
||
//return Json(bll.Add(model));
|
||
}
|
||
|
||
|
||
#region 菜单维护
|
||
/// <summary>
|
||
/// 微信菜单管理
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public ActionResult Menu()
|
||
{
|
||
return View();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微信菜单类型
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public JsonResult getCDLX()
|
||
{
|
||
return Json(
|
||
new[]
|
||
{
|
||
new { id="zu",name="菜单组" },
|
||
new { id="click",name="点击推事件" },
|
||
new { id="view",name="跳转URL" }
|
||
}
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取菜单列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public string getMeun()
|
||
{
|
||
// string sql = "select * from menu";
|
||
var dt = new BLL.InfectionMenuBll().getMenuInfection();
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(dt);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取上级菜单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public string getSJCD()
|
||
{
|
||
var dt = new BLL.InfectionMenuBll().getSJCDInfection();
|
||
var dr = new Models.InfectionMenuModel
|
||
{
|
||
id = 0,
|
||
name = "顶级菜单"
|
||
};
|
||
dt.Insert(0, dr);
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(dt);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除菜单
|
||
/// </summary>
|
||
/// <param name="id">菜单ID</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public JsonResult delCD(int id)
|
||
{
|
||
return Json(new BLL.InfectionMenuBll().delCdInfection(id));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存菜单
|
||
/// </summary>
|
||
/// <param name="m">菜单实体</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public JsonResult saveCD(Models.InfectionMenuModel m)
|
||
{
|
||
|
||
return Json(new BLL.InfectionMenuBll().saveCDInfection(m));
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 发送菜单
|
||
|
||
/// <summary>
|
||
/// 提交微信菜单
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public string CreateWXMenu()
|
||
{
|
||
List<button> btns = new List<button>();
|
||
var dt = new BLL.InfectionMenuBll().getMenuInfection();
|
||
var drs = dt.Where(t => t.pid == 0);
|
||
foreach (var dr in drs)
|
||
{
|
||
var btn = new button { name = dr.name };
|
||
var zcds = dt.Where(t => t.pid == dr.id);
|
||
var enumerable = zcds as InfectionMenuModel[] ?? zcds.ToArray();
|
||
if (enumerable.Any())
|
||
{
|
||
btn.sub_button = new List<button>();
|
||
foreach (var zdr in enumerable)
|
||
{
|
||
var zcd = new button
|
||
{
|
||
name = zdr.name,
|
||
type = zdr.cdlx
|
||
};
|
||
if (zcd.type == "click")
|
||
{
|
||
zcd.key = zdr.key;
|
||
}
|
||
else if (zcd.type == "view")
|
||
{
|
||
zcd.url = zdr.url;
|
||
}
|
||
btn.sub_button.Add(zcd);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
btn.type = dr.cdlx;
|
||
if (btn.type == "click")
|
||
{
|
||
btn.key = dr.key;
|
||
}
|
||
else if (btn.type == "view")
|
||
{
|
||
btn.url = dr.url;
|
||
}
|
||
}
|
||
btns.Add(btn);
|
||
}
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new { button = btns });
|
||
WebClient wc = new WebClient();
|
||
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
||
log4net.LogManager.GetLogger(this.GetType()).Info(postData);
|
||
var result = wc.UploadData("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + Common.Global.getAccessTokenInfection.access_token, System.Text.Encoding.UTF8.GetBytes(postData));
|
||
string jg = System.Text.Encoding.UTF8.GetString(result);
|
||
return jg;
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 排队
|
||
[AllowAnonymous]
|
||
public string getpdxx()
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "获取关注信息失败请重新打开排队页面!" });
|
||
}
|
||
string session = Session["openuser"].ToString();
|
||
Models.PD_XX pdxx = new BLL.PaiDuiJiaoHaoBLL().getpdxx(session);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(Newtonsoft.Json.JsonConvert.SerializeObject(ml));
|
||
if (pdxx == null)
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Stste = 0 });
|
||
else
|
||
{
|
||
|
||
ViewBag.pdid = pdxx.id;
|
||
var pdxx1 = new BLL.JiezhongmianyitiaomaModelBll().getpdxx(session);
|
||
/*
|
||
ViewBag.wdhm = pdxx.hm;
|
||
ViewBag.ddrs = pdxx1.ddrs;
|
||
ViewBag.dqhm = pdxx1.dqhm;
|
||
if (pdxx1.dqhm > pdxx.hm)
|
||
{
|
||
ViewBag.btntext = "重新排队";
|
||
}
|
||
else
|
||
{
|
||
ViewBag.btntext = "取消排队";
|
||
}*/
|
||
//return View();
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { pdid = pdxx.id, wdhm = pdxx.hm, ddrs = pdxx1.ddrs, dqhm = pdxx1.dqhm });
|
||
}
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult paidui()
|
||
{
|
||
|
||
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
Session["openuser"] = openid.openid;
|
||
HttpCookie hc = new HttpCookie("openuser");
|
||
hc.Value = openid.openid;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
|
||
string session = Session["openuser"].ToString();
|
||
JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
var ml = bll.getListByopenid(session);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().GetType()).Info(Newtonsoft.Json.JsonConvert.SerializeObject(ml));
|
||
if (ml.Count > 0)
|
||
{
|
||
|
||
Models.PD_XX pdxx = new BLL.PaiDuiJiaoHaoBLL().getpdxx(session);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(Newtonsoft.Json.JsonConvert.SerializeObject(ml));
|
||
if (pdxx == null)
|
||
return RedirectToAction("quhao");
|
||
else
|
||
{
|
||
ViewBag.pdid = pdxx.id;
|
||
var pdxx1 = new BLL.JiezhongmianyitiaomaModelBll().getpdxx(session);
|
||
ViewBag.wdhm = pdxx.hm;
|
||
ViewBag.ddrs = pdxx1.ddrs;
|
||
ViewBag.dqhm = pdxx1.dqhm;
|
||
if (pdxx1.dqhm > pdxx.hm)
|
||
{
|
||
ViewBag.btntext = "重新排队";
|
||
}
|
||
else
|
||
{
|
||
ViewBag.btntext = "取消排队";
|
||
}
|
||
return View();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return View("bd");
|
||
}
|
||
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public JsonResult qxpd(string pdid)
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Json(new { State = 0, Message = "获取关注信息失败请重新打开排队页面!" });
|
||
}
|
||
return Json(new BLL.PaiDuiJiaoHaoBLL().qxpd(pdid));
|
||
//return View();
|
||
}
|
||
[AllowAnonymous]
|
||
public ActionResult quhao()
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
Session["openuser"] = openid.openid;
|
||
HttpCookie hc = new HttpCookie("openuser");
|
||
hc.Value = openid.openid;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
string session = Session["openuser"].ToString();
|
||
JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
var ml = bll.getListByopenid(session);
|
||
if (ml.Count > 0)
|
||
{
|
||
var etlist = bll.getetlistbybdxx(session);
|
||
ViewBag.etlist = new SelectList(etlist, "id", "username");
|
||
ViewBag.pdrs = new BLL.PaiDuiJiaoHaoBLL().getPdrs();
|
||
return View();
|
||
}
|
||
else
|
||
{
|
||
return View("bd");
|
||
}
|
||
|
||
}
|
||
[AllowAnonymous]
|
||
public JsonResult savequhao(string etid)
|
||
{
|
||
|
||
PaiDuiJiaoHaoBLL bll = new PaiDuiJiaoHaoBLL();
|
||
int ietid = 0;
|
||
if (!int.TryParse(etid, out ietid))
|
||
{
|
||
return Json(new { State = 0, Message = "您的儿童信息有问题,请选择儿童。" });
|
||
}
|
||
var result = bll.JiaoHao(ietid);
|
||
if (result.State == 1)
|
||
{
|
||
IConnection connection;
|
||
ISession session;
|
||
IMessageProducer prod;
|
||
string address = System.Configuration.ConfigurationManager.AppSettings["MQAddress"];
|
||
IConnectionFactory factory = new ConnectionFactory(address);
|
||
connection = factory.CreateConnection();
|
||
connection.ClientId = Dns.GetHostName() + "_gxpdrs";
|
||
connection.Start();
|
||
//Create the Session
|
||
session = connection.CreateSession();
|
||
|
||
//Create the Producer for the topic/queue
|
||
prod = session.CreateProducer(
|
||
new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("sxpdrs"));
|
||
prod.DeliveryMode = MsgDeliveryMode.Persistent;
|
||
var imesg = prod.CreateTextMessage();
|
||
imesg.Text = result.Message.Split('|')[2];
|
||
//imesg.Properties.SetString("dept_code", ksbh);
|
||
prod.Send(imesg, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue);
|
||
prod.Close();
|
||
prod = session.CreateProducer(
|
||
new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("gxpdlb"));
|
||
prod.DeliveryMode = MsgDeliveryMode.Persistent;
|
||
imesg = prod.CreateTextMessage();
|
||
imesg.Text = "gxpdlb";
|
||
//imesg.Properties.SetString("dept_code", ksbh);
|
||
prod.Send(imesg, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue);
|
||
|
||
|
||
prod.Close();
|
||
|
||
prod = session.CreateProducer(
|
||
new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("sxpdrs"));
|
||
prod.DeliveryMode = MsgDeliveryMode.Persistent;
|
||
imesg = prod.CreateTextMessage();
|
||
imesg.Text = "";
|
||
//imesg.Properties.SetString("dept_code", ksbh);
|
||
prod.Send(imesg, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue);
|
||
prod.Close();
|
||
session.Close();
|
||
connection.Close();
|
||
return Json(new { State = 1, Message = result.Message.Split('|')[2] });
|
||
}
|
||
return Json(result);
|
||
}
|
||
[AllowAnonymous]
|
||
public ActionResult my()
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
Session["openuser"] = openid.openid;
|
||
HttpCookie hc = new HttpCookie("openuser");
|
||
hc.Value = openid.openid;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
string session = Session["openuser"].ToString();
|
||
JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
var ml = bll.getListByopenid(session);
|
||
if (ml.Count > 0)
|
||
{
|
||
var etlist = bll.getetlistbybdxx(session);
|
||
ViewBag.etlist = new SelectList(etlist, "id", "username");
|
||
return View();
|
||
}
|
||
else
|
||
{
|
||
return View("bd");
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 获取微信用户信息
|
||
public string GetOAuthOpenId(string code)
|
||
{
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("code:"+code);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("YMAppId:" + Common.Global.YMAppId);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("YMAppsecret:" + Common.Global.YMAppsecret);
|
||
//return "";
|
||
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Common.Global.InfectionAppId + "&secret=" + Common.Global.InfectionAppsecret + "&code=" + code + "&grant_type=authorization_code";
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||
Stream stream = response.GetResponseStream(); //获取响应的字符串流
|
||
if (stream != null)
|
||
{
|
||
StreamReader sr = new StreamReader(stream); //创建一个stream读取流
|
||
string html = sr.ReadToEnd(); //从头读到尾,放到字符串html李米
|
||
sr.Close();
|
||
stream.Close();
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(html);
|
||
|
||
return html;
|
||
}
|
||
return "";
|
||
}
|
||
[AllowAnonymous]
|
||
public string getetxx(string etid)
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "获取关注信息失败请重新打开儿童信息绑定页面!" });
|
||
}
|
||
var m = new BLL.JiezhongmianyitiaomaModelBll().getetxx(etid, Session["openuser"].ToString());
|
||
if (m == null)
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0 });
|
||
}
|
||
else
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, et = m });
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 绑定解绑
|
||
[AllowAnonymous]
|
||
public ActionResult bd()
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
Session["openuser"] = openid.openid;
|
||
HttpCookie hc = new HttpCookie("openuser");
|
||
hc.Value = openid.openid;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
[AllowAnonymous]
|
||
public JsonResult checkBd(string username, string barcode, string yetgx)
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Json(new { State = 0, Message = "获取关注信息失败请重新打开儿童信息绑定页面!" });
|
||
}
|
||
JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
var result = bll.checkBarcode(username, barcode, yetgx, Session["openuser"].ToString());
|
||
return Json(result);
|
||
}
|
||
[AllowAnonymous]
|
||
public JsonResult jiebang(string etid)
|
||
{
|
||
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Json(new { State = 0, Message = "获取关注信息失败请重新打开儿童信息绑定页面!" });
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(etid))
|
||
{
|
||
|
||
return Json(new JiezhongmianyitiaomaModelBll().jb(etid, Session["openuser"].ToString()));
|
||
//return Json(new { State = 1, Message = "解除绑定失败!" });
|
||
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = "解除绑定失败!" });
|
||
}
|
||
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public JsonResult saveBd(JiezhongmianyitiaomaModel model)
|
||
{
|
||
if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
{
|
||
return Json(new { State = 0, Message = "获取关注信息失败请重新打开儿童信息绑定页面!" });
|
||
}
|
||
model.openid = Session["openuser"].ToString();
|
||
|
||
var yzmbll = new BLL.DuanXinYanZhengBll();
|
||
//int iyzmid;
|
||
//int.TryParse(yzmid, out iyzmid);
|
||
if (string.IsNullOrEmpty(model.yzmid))
|
||
{
|
||
return Json(new { State = 0, Message = "手机验证码不正确!" });
|
||
}
|
||
var yzm = yzmbll.getYZMById(model.yzmid);
|
||
if (yzm == null)
|
||
{
|
||
return Json(new { State = 0, Message = "手机验证码不正确!" });
|
||
}
|
||
if (yzm.ShouJiHao != model.sjh)
|
||
{
|
||
return Json(new { State = 0, Message = "手机号码和获取验证码的手机号码不一致!" });
|
||
}
|
||
if ((DateTime.Now - yzm.sendtime).TotalMinutes > yzm.YanZhengYouXiaoQi)
|
||
{
|
||
return Json(new { State = 0, Message = "验证码已经超过有效期!" });
|
||
}
|
||
if (yzm.state != 0)
|
||
{
|
||
return Json(new { State = 0, Message = "验证码已经使用不能重复验证!" });
|
||
}
|
||
|
||
if (yzm.smscode != model.yzm)
|
||
{
|
||
return Json(new { State = 0, Message = "手机验证码不正确!" });
|
||
}
|
||
|
||
JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
OperationResult result;
|
||
|
||
result = bll.bd(model);
|
||
if (result.State == 1)
|
||
{
|
||
yzmbll.YanZhenged(yzm);
|
||
}
|
||
return Json(result);
|
||
}
|
||
#endregion
|
||
#region 微信提示
|
||
[AllowAnonymous]
|
||
public ActionResult WXTS(string id)
|
||
{
|
||
|
||
return View(new BLL.Common().GetModelBy(id));
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 获取手机验证码
|
||
/// </summary>
|
||
/// <param name="Mobile">手机号</param>
|
||
/// <returns>验证码ID</returns>
|
||
[AllowAnonymous]
|
||
public JsonResult getsjyzm(string Mobile)
|
||
{
|
||
if (System.Text.RegularExpressions.Regex.IsMatch(Mobile, "^1[3|4|5|7|8]\\d{9}$"))
|
||
{
|
||
var dxyz = new BLL.DuanXinYanZhengBll();
|
||
string cookieid = Guid.NewGuid().ToString();// Request.Cookies["clientid"].Value;
|
||
var yzm = dxyz.getYanZheng(Session.SessionID, cookieid, Request.UserHostAddress, Mobile);
|
||
if (yzm.id == 0)
|
||
{
|
||
return Json(new { State = 0, Message = yzm.bz });
|
||
}
|
||
else
|
||
{
|
||
var commonbll = new BLL.Common();
|
||
string yddx = commonbll.getParm_Value("qyyddx", "false", "是否启用移动短信");
|
||
if (yddx == "false")
|
||
{
|
||
string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
|
||
string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
|
||
string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
|
||
string dxmb = commonbll.getParm_Value("aldxmb_ym", "SMS_135797401", "疫苗绑定短信模版");
|
||
//string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
|
||
//string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
|
||
//var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
|
||
//var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
|
||
//var fz = Session["FenZhan"] as Model.FenZhan;
|
||
//Common.SendMsg.Send(sjh, yznr, fz.id);
|
||
String product = "Dysmsapi";//短信API产品名称
|
||
String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
|
||
String accessKeyId = AccessKeyID;//你的accessKeyId
|
||
String accessKeySecret = AccessKeySecret;//你的accessKeySecret
|
||
|
||
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
|
||
//IAcsClient client = new DefaultAcsClient(profile);
|
||
// SingleSendSmsRequest request = new SingleSendSmsRequest();
|
||
|
||
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
|
||
IAcsClient acsClient = new DefaultAcsClient(profile);
|
||
SendSmsRequest request = new SendSmsRequest();
|
||
try
|
||
{
|
||
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
|
||
request.PhoneNumbers = Mobile;
|
||
//必填:短信签名-可在短信控制台中找到
|
||
request.SignName = qm;
|
||
//必填:短信模板-可在短信控制台中找到
|
||
request.TemplateCode = dxmb;
|
||
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
||
request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { code = yzm.smscode });
|
||
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
|
||
//request.OutId = "21212121211";
|
||
//请求失败这里会抛ClientException异常
|
||
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
|
||
|
||
//System.Console.WriteLine(sendSmsResponse.Message);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
|
||
|
||
}
|
||
catch (ServerException e)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
|
||
//System.Console.WriteLine("Hello World!");
|
||
//return Json(new { State = 0, Message = e.Message});
|
||
|
||
}
|
||
catch (ClientException e)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
|
||
//return Json(new { State = 0, Message = e.Message});
|
||
}
|
||
return Json(new { State = 1, Message = yzm.id.ToString() });
|
||
}
|
||
else
|
||
{
|
||
//http://112.35.1.155:1992/sms/norsubmit
|
||
string ydhttp = commonbll.getParm_Value("ydhttp", "http://112.35.1.155:1992/sms/tmpsubmit", "移动短信地址");
|
||
var req = new Models.duanxin.msend();
|
||
req.ecName = commonbll.getParm_Value("yddxqymc", "德州市德城区疾病预防控制中心", "企业名称");
|
||
req.apId = commonbll.getParm_Value("yddxapId", "jkoa", "接口账号用户名");
|
||
req.mobiles = yzm.ShouJiHao;
|
||
req.sign = commonbll.getParm_Value("yddxsign", "d37CYmrbG", "签名编码");
|
||
//req.content = "您正在绑定宝宝的接种信息,您的验证码是" + yzm.smscode + "!请确认提交信息准确,如有不明请咨询登记窗口!";
|
||
req.templateId = "f9037ad4c79b4212b9fdcd69f73d05c2";
|
||
req.addSerial = "";
|
||
|
||
string[] parms = new string[1];
|
||
parms[0] = yzm.smscode;
|
||
req.parms = Newtonsoft.Json.JsonConvert.SerializeObject(parms);
|
||
var md5 = MD5.Create();
|
||
//secretKey
|
||
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(req.ecName + req.apId + commonbll.getParm_Value("yddxsecretKey", "a7551898", "短信接口密码") + req.templateId + req.mobiles + req.parms + req.sign));
|
||
var sb = new StringBuilder();
|
||
foreach (byte b in bs)
|
||
{
|
||
sb.Append(b.ToString("x2"));
|
||
}
|
||
req.mac = sb.ToString().ToLower();
|
||
WebClient wc = new WebClient();
|
||
string upstr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
|
||
upstr = upstr.Replace("parms", "params");
|
||
//new {params }
|
||
//upstr.Insert(upstr.Length-1,",")
|
||
byte[] resp = wc.UploadData(ydhttp, System.Text.Encoding.UTF8.GetBytes(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(upstr))));
|
||
var nres = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.duanxin.nrecive>(System.Text.Encoding.UTF8.GetString(resp));
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(System.Text.Encoding.UTF8.GetString(resp));
|
||
return Json(new { State = 1, Message = yzm.id.ToString() });
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = "请输入正确的手机号码!" });
|
||
}
|
||
}
|
||
|
||
public string mytest()
|
||
{
|
||
var m = new BLL.JiezhongmianyitiaomaModelBll().getpdxx("");
|
||
return Newtonsoft.Json.JsonConvert.SerializeObject(m);
|
||
}
|
||
|
||
#region 素材维护
|
||
/// <summary>
|
||
/// 微信素材管理
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public ActionResult Editor(string id)
|
||
{
|
||
Models.SystemParmsModel parm = new BLL.Common().GetModelBy(id);
|
||
return View(parm);
|
||
}
|
||
|
||
[HttpPost]
|
||
[ValidateInput(false)]
|
||
public JsonResult SaveWeiXinNR(SystemParmsModel sp)
|
||
{
|
||
//sp.id = int.Parse(Request.Form["id"]);
|
||
var b = new BLL.Common().Update(sp);
|
||
if (b)
|
||
{
|
||
return Json(new { State = 1, Message = "保存成功!" });
|
||
}
|
||
else
|
||
{
|
||
return Json(new { State = 0, Message = "保存失败!" });
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 构造参数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public string GetJsApiParameters(string openid,int amount,string mch_billno)
|
||
{
|
||
//int iMin = 1000;
|
||
//int iMax = 9999;
|
||
//Random rd = new Random();//构造随机数
|
||
|
||
//string strMch_billno = Common.Global.InfectionMchId + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(iMin, iMax).ToString();
|
||
WxPayData jsApiParam = new WxPayData();
|
||
jsApiParam.SetValue("act_name", "艾防健康大礼包");//活动名称
|
||
jsApiParam.SetValue("client_ip", "58.56.244.46");//这里填写的是我本机的内网ip,实际应用不知道需不需要改。
|
||
jsApiParam.SetValue("mch_billno", mch_billno);//商户订单号,商户订单号(每个订单号必须唯一)组成:mch_id+yyyymmdd+10位一天内不能重复的数字。 接口根据商户订单号支持重入,如出现超时可再调用。
|
||
jsApiParam.SetValue("mch_id", Common.Global.InfectionMchId);//商户号,微信支付分配的商户号
|
||
jsApiParam.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串,不长于32位
|
||
jsApiParam.SetValue("remark", "备注信息,艾防测试");//备注信息
|
||
jsApiParam.SetValue("re_openid", openid);//接收者的openid
|
||
jsApiParam.SetValue("send_name", "德城疾控中心");//商户名称,红包发送者名称
|
||
jsApiParam.SetValue("total_amount", amount);//红包金额,单位分
|
||
jsApiParam.SetValue("total_num", 1);//红包发放总人数
|
||
jsApiParam.SetValue("scene_id", "PRODUCT_5");//红包发放总人数
|
||
jsApiParam.SetValue("wishing", "感谢您参加德城健康e路!");//红包祝福语
|
||
jsApiParam.SetValue("wxappid", Common.Global.InfectionAppId);//公众账号appid,微信分配的公众账号ID(企业号corpid即为此appId)。接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),不能为APP的appid(在open.weixin.qq.com申请的)。
|
||
jsApiParam.SetValue("sign", jsApiParam.MakeSign());//签名,切记,这个签名参数必须放在最后,因为他生成的签名,跟前面的参数有关系
|
||
|
||
string parameters = jsApiParam.ToXml();
|
||
return parameters;
|
||
}
|
||
|
||
public string GetHBParameters(string mch_billno)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("1=====================" + 1);
|
||
int iMin = 1000;
|
||
int iMax = 9999;
|
||
Random rd = new Random();//构造随机数
|
||
string strMch_billno = Common.Global.InfectionMchId + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(iMin, iMax).ToString();
|
||
WxPayData jsApiParam = new WxPayData();
|
||
jsApiParam.SetValue("mch_billno", mch_billno);//商户订单号,商户订单号(每个订单号必须唯一)组成:mch_id+yyyymmdd+10位一天内不能重复的数字。 接口根据商户订单号支持重入,如出现超时可再调用。
|
||
jsApiParam.SetValue("mch_id", Common.Global.InfectionMchId);//商户号,微信支付分配的商户号
|
||
jsApiParam.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串,不长于32位
|
||
jsApiParam.SetValue("bill_type", "MCHT");//通过商户订单号获取红包信息。
|
||
jsApiParam.SetValue("appid", Common.Global.InfectionAppId);//公众账号appid,微信分配的公众账号ID(企业号corpid即为此appId)。接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),不能为APP的appid(在open.weixin.qq.com申请的)。
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("jsApiParam=====================" + jsApiParam.ToXml());
|
||
jsApiParam.SetValue("sign", jsApiParam.MakeSignHB());//签名,切记,这个签名参数必须放在最后,因为他生成的签名,跟前面的参数有关系
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("9=====================" + 9);
|
||
string parameters = jsApiParam.ToXml();
|
||
return parameters;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交请求
|
||
/// </summary>
|
||
/// <param name="posturl"></param>
|
||
/// <param name="postData"></param>
|
||
/// <returns></returns>
|
||
public string WxRedPackPost(string posturl, string postData)
|
||
{
|
||
Stream outstream = null;
|
||
Stream instream = null;
|
||
StreamReader sr = null;
|
||
HttpWebResponse response = null;
|
||
HttpWebRequest request = null;
|
||
Encoding encoding = Encoding.UTF8;
|
||
byte[] data = encoding.GetBytes(postData);
|
||
// 准备请求...
|
||
try
|
||
{
|
||
//CerPath证书路径,这里是本机的路径,实际应用中,按照实际情况来填写
|
||
string certPath = @"D:\XinYiLu\" + WxPayConfig.SSLCERT_PATH;
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("certPath====================="+certPath);
|
||
//证书密码
|
||
string password = Common.Global.InfectionMchId;
|
||
X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath, password, X509KeyStorageFlags.MachineKeySet);
|
||
|
||
// 设置参数
|
||
request = WebRequest.Create(posturl) as HttpWebRequest;
|
||
CookieContainer cookieContainer = new CookieContainer();
|
||
request.CookieContainer = cookieContainer;//不可少(个人理解为,返回的时候需要验证)
|
||
request.AllowAutoRedirect = true;
|
||
request.Method = "POST";
|
||
request.ContentType = "text/xml";
|
||
request.ContentLength = data.Length;
|
||
request.ClientCertificates.Add(cert);//添加证书请求
|
||
outstream = request.GetRequestStream();
|
||
outstream.Write(data, 0, data.Length);
|
||
outstream.Close();
|
||
//发送请求并获取相应回应数据
|
||
response = request.GetResponse() as HttpWebResponse;
|
||
//直到request.GetResponse()程序才开始向目标网页发送Post请求
|
||
instream = response.GetResponseStream();
|
||
sr = new StreamReader(instream, encoding);
|
||
//返回结果网页(html)代码
|
||
string content = sr.ReadToEnd();
|
||
string err = string.Empty;
|
||
return content;
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string err = ex.Message;
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("err=================" + err);
|
||
return string.Empty;
|
||
}
|
||
}
|
||
[AllowAnonymous]
|
||
public string sendRedPack(string openid,int amount,string mch_billno) {
|
||
try {
|
||
//string parameters = GetJsApiParameters("onnNC1rph1aY0jnKcfrFf4qv8Ni0",50);
|
||
string return_value = "";
|
||
int iMin = 1000;
|
||
int iMax = 9999;
|
||
Random rd = new Random();//构造随机数
|
||
|
||
string strMch_billno = Common.Global.InfectionMchId + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(iMin, iMax).ToString();
|
||
string parameters = GetJsApiParameters(openid, amount, mch_billno);
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("parameters=====================" + parameters);
|
||
string message = WxRedPackPost("https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack", parameters);
|
||
var doc = new XmlDocument();
|
||
doc.LoadXml(message);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("message=================" + message);
|
||
var return_code = doc.SelectSingleNode("/xml/return_code");
|
||
//log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("returncode=================" + return_code);
|
||
if (return_code.InnerText.Trim().Equals("SUCCESS")) {
|
||
//var send_listid = doc.SelectSingleNode("/xml/send_listid");
|
||
////log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("send_listid=================" + send_listid);
|
||
//if (!string.IsNullOrEmpty(send_listid.InnerText)) {
|
||
// return_value = send_listid.InnerText.Trim();
|
||
//}
|
||
return_value = mch_billno;
|
||
}
|
||
return return_value;
|
||
}
|
||
catch (Exception ex) {
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("exception=================" + ex.Message);
|
||
return "";
|
||
}
|
||
}
|
||
|
||
//获取微信红包状态
|
||
[AllowAnonymous]
|
||
public string checkRedPack(string mch_billno)
|
||
{
|
||
try
|
||
{
|
||
//string parameters = GetJsApiParameters("onnNC1rph1aY0jnKcfrFf4qv8Ni0",50);
|
||
string return_value = "";
|
||
//int iMin = 1000;
|
||
//int iMax = 9999;
|
||
//Random rd = new Random();//构造随机数
|
||
|
||
//string strMch_billno = Common.Global.InfectionMchId + DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(iMin, iMax).ToString();
|
||
string parameters = GetHBParameters(mch_billno);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("parameters=====================" + parameters);
|
||
string message = WxRedPackPost("https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo", parameters);
|
||
var doc = new XmlDocument();
|
||
doc.LoadXml(message);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("message=================" + message);
|
||
var return_code = doc.SelectSingleNode("/xml/return_code");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("returncode=================" + return_code.InnerText);
|
||
if (return_code.InnerText.Trim().Equals("SUCCESS"))
|
||
{
|
||
var result_code = doc.SelectSingleNode("/xml/result_code");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("result_code=================" + result_code.InnerText);
|
||
if (result_code.InnerText.Trim().Equals("SUCCESS")) {
|
||
var status = doc.SelectSingleNode("/xml/status");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("status=================" + status.InnerText);
|
||
if (!string.IsNullOrEmpty(status.InnerText))
|
||
{
|
||
return_value = status.InnerText.Trim();
|
||
}
|
||
}
|
||
}
|
||
return return_value;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("exception=================" + ex.Message);
|
||
return "";
|
||
}
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult userCheckIndex()
|
||
{
|
||
return View();
|
||
}
|
||
[AllowAnonymous]
|
||
public JsonResult userCheck(string user_id)
|
||
{
|
||
InfectionCheckModel model = new InfectionCheckModel();
|
||
model.user_id = int.Parse(user_id);
|
||
model.state = 1;
|
||
model.check_date = DateTime.Now.ToString("yyyy-MM-dd");
|
||
model.create_time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
|
||
InfectionCheckBll bll = new InfectionCheckBll();
|
||
return Json(bll.SaveData(model));
|
||
}
|
||
|
||
public int getUserCheck(string user_id)
|
||
{
|
||
InfectionCheckBll bll = new InfectionCheckBll();
|
||
int i = bll.checkToday(user_id);
|
||
return i;
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public JsonResult getCheckList()
|
||
{
|
||
string user_id = Session["InfectionUserID"].ToString();
|
||
//string user_id = "1";
|
||
var bll = new BLL.InfectionCheckBll();
|
||
List<Models.InfectionCheckModel> checkList = bll.GetAllDataList(user_id);
|
||
return Json(checkList);
|
||
}
|
||
|
||
public JsonResult getCheckList2()
|
||
{
|
||
//string user_id = Session["InfectionUserID"].ToString();
|
||
string user_id = "1";
|
||
var bll = new BLL.InfectionCheckBll();
|
||
List<Models.InfectionCheckModel> checkList = bll.GetAllDataList(user_id);
|
||
return Json(checkList);
|
||
}
|
||
|
||
//public ActionResult personInfoEntering()
|
||
//{
|
||
// return View();
|
||
//}
|
||
|
||
|
||
|
||
|
||
//[AllowAnonymous]
|
||
//public ActionResult personInfoEntering()
|
||
//{
|
||
|
||
|
||
// if (Session["openuser"] == null || Session["openuser"].ToString() == "")
|
||
// {
|
||
// string code = Request.QueryString["code"];
|
||
// if (string.IsNullOrEmpty(code))
|
||
// {
|
||
// return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
// "&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
// "&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
// }
|
||
// string openidstr = GetOAuthOpenId(code);
|
||
// var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
// Session["InfectionOpenId"] = openid.openid;
|
||
// string session = Session["openuser"].ToString();
|
||
// string user_id = GetUserIDByOpenID(session);
|
||
// HttpCookie hc = new HttpCookie("InfectionOpenId");
|
||
// hc.Value = user_id;
|
||
// Session["InfectionUserId"] = user_id;
|
||
// Response.Cookies.Add(hc);
|
||
// }
|
||
|
||
// //string session = Session["openuser"].ToString();
|
||
// //JiezhongmianyitiaomaModelBll bll = new JiezhongmianyitiaomaModelBll();
|
||
// //var ml = bll.getListByopenid(session);
|
||
// ////log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().GetType()).Info(Newtonsoft.Json.JsonConvert.SerializeObject(ml));
|
||
// //if (ml.Count > 0)
|
||
// //{
|
||
|
||
// // return View();
|
||
// //}
|
||
// //else
|
||
// //{
|
||
// return View();
|
||
// //}
|
||
|
||
//}
|
||
|
||
#region 微信页面
|
||
|
||
/// <summary>
|
||
/// 根据openid获取userid
|
||
/// </summary>
|
||
/// <param name="openid"></param>
|
||
/// <returns></returns>
|
||
[AllowAnonymous]
|
||
public string GetUserIDByOpenID(string openid)
|
||
{
|
||
return new BLL.InfectionOpenUserBll().GetDataByOpenid(openid);
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult AddSessionData(string view)
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult inspectResult()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult inspectResultQuery()
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("-------------------------------!!!!!!!!!!!!!!!!!!!!");
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(Session);
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(code);
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(Url.Encode(Request.Url.AbsoluteUri));
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(openidstr);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(openid);
|
||
Session["InfectionOpenId"] = openid.openid;
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(openid.openid);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(Session["InfectionOpenId"]);
|
||
string session = Session["InfectionOpenId"].ToString();
|
||
string user_id = GetUserIDByOpenID(session);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(user_id);
|
||
HttpCookie hc = new HttpCookie("InfectionOpenId");
|
||
hc.Value = user_id;
|
||
Session["InfectionUserId"] = user_id;
|
||
Response.Cookies.Add(hc);
|
||
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("+++++++++++++++++++++///////////////");
|
||
}
|
||
return View("inspectResultQuery");
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult personInfo()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult personInfoAudit()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult personInfoEntering()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult signIn()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult subscribeEdit()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult subscribeInfo()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult userInfo()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult userSubscribe()
|
||
{
|
||
if (Session["InfectionUserID"] == null || Session["InfectionUserID"].ToString() == "")
|
||
{
|
||
string code = Request.QueryString["code"];
|
||
if (string.IsNullOrEmpty(code))
|
||
{
|
||
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.InfectionAppId +
|
||
"&redirect_uri=" + Url.Encode(Request.Url.AbsoluteUri) +
|
||
"&response_type=code&scope=snsapi_base#wechat_redirect");
|
||
}
|
||
string openidstr = GetOAuthOpenId(code);
|
||
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
|
||
string user_id = GetUserIDByOpenID(openid.openid);
|
||
Session["InfectionUserID"] = user_id;
|
||
HttpCookie hc = new HttpCookie("InfectionUserID");
|
||
hc.Value = user_id;
|
||
Response.Cookies.Add(hc);
|
||
}
|
||
return View();
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 产生随机数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[AllowAnonymous]
|
||
public string RandomNumber()
|
||
{
|
||
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||
Random random = new Random();
|
||
string returnValue = dateTime + random.Next(99999, 1000000).ToString();
|
||
return returnValue;
|
||
}
|
||
|
||
[AllowAnonymous]
|
||
public ActionResult personInfoEnteringPc()
|
||
{
|
||
Session["InfectionUserID"] = "1";
|
||
return View("personInfoEntering");
|
||
}
|
||
|
||
public string xmlTest() {
|
||
string xml = @"<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[发放成功.]]></return_msg><result_code><![CDATA[SUCCESS]]></result_code><err_code><![CDATA[0]]></err_code><err_code_des><![CDATA[发放成功.]]></err_code_des><mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno><mch_id>10010404</mch_id><wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid><re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid><total_amount>1</total_amount></xml>";
|
||
var doc = new XmlDocument();
|
||
doc.LoadXml(xml);
|
||
var return_code = doc.SelectSingleNode("/xml/return_code");
|
||
return return_code.InnerText.Trim();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 产生推荐码
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
/// [AllowAnonymous]
|
||
public string RecommendNumber()
|
||
{
|
||
string returnValue = new Random().Next(0, 99999).ToString("D5");
|
||
return returnValue;
|
||
}
|
||
|
||
}
|
||
} |