You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Mobile/DAL/TemplateMessage/TemplateMessageDAL.cs

90 lines
3.2 KiB
C#

3 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.Mobile.Models.Login;
using DSWeb.TruckMng.Helper;
using DSWeb.Areas.Mobile.Models;
using DSWeb.Areas.Mobile.Models.TemplateMessage;
using System.Net;
using System.IO;
using DSWeb.Areas.Mobile.DAL.TemplateMessage;
using System.Configuration;
namespace DSWeb.Areas.Mobile.DAL
{
public class TemplateMessageDAL
{
/// <summary>
///
/// </summary>
/// <param name="tempid">
/// 0:付费申请
/// 1:应收应付审批
/// </param>
/// <param name="bsno">[WorkFlow_Using].BSNO 业务编号</param>
/// <returns></returns>
public static void Send ( int tempid,string bsno) {
DBLog.Log("Send","Begin","-2");
try
{
DBLog.Log("Send", "-1");
var appid = ConfigurationManager.AppSettings["appid"];
DBLog.Log("Send", "0");
if (appid == null || appid.ToString() == "")
{
DBLog.Log("Send", "1");
DBLog.Log("appid == null || appid.ToString() != \"\"");
return;
}
//判断该票业务是否需要微信推送
////ch_fee_payapplication.wxpush字段是否为1
string checkSql = "select wxpush from ch_fee_payapplication where billno = '" + bsno + "'";
Database db = DatabaseFactory.CreateDatabase();
DBLog.Log("Send", "2");
var rst = db.ExecuteScalar(CommandType.Text, checkSql);
DBLog.Log("Send", "3");
int wxpush = 0;
if (rst != null && rst != DBNull.Value && rst.ToString() != "")
{
wxpush = Convert.ToInt32(rst);
}
if (wxpush == 0)
{
DBLog.Log("send", "wxpush==0", "bsno:" + bsno);
return;
}
string accessToken = AccessTokenDAL.GetAccessToken();
List<TMBase> list = TemplateMessageModelConverter.CreateModel(tempid, bsno);
string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", accessToken);
DBLog.Log("Send", "List.Count", list.Count.ToString());
foreach (TMBase tm in list)
{
string jsonData = JsonConvert.Serialize(new { tm });
//格式化为微信接口需要的字符串格式
jsonData = jsonData.Substring(11);
jsonData = jsonData.Substring(0, jsonData.Length - 1);
string postrst = HttpHelper.HttpPost(url, jsonData);
DBLog.Log("Send", "Result", postrst);
}
}
catch (Exception ex)
{
DBLog.Log("send","error",ex.Message+ex.Source+ex.StackTrace+ex.TargetSite+ex.InnerException);
throw;
}
}
}
}