日度归档:2016年3月24日

微信公众号开发 – 获取所有关注的用户openid

需要的类 用于反序列化

public class GuanZhuModel2
{
    public int total { get; set; }
    public int count { get; set; }
    public OpenIdListData data { get; set; }
    public string next_openid { get; set; }
}
public class OpenIdListData
{
    /// 
    /// OPENID的列表
    /// 
    public List openid { get; set; }
}

具体方法:

string returnStr = HttpUtil.Send("", "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + Convert.ToString(PayCenter.getCache("wxModelAccess")) + "&next_openid=");
       
        var obj = JsonConvert.DeserializeObject(returnStr);
        for (int i = 0; i < obj.data.openid.Count; i++)
        {
            var openid = Convert.ToString(obj.data.openid[i]);
            UserOpen openmodel = new UserOpenDAL().GetOpenIDOrType(openid, 1);
            new WXAPICommon(null, null, null).ReturnTxt(openid, "尊敬的用户,由于惠号网帐户体系升级,您的帐户类型已变更!");
            if (openmodel == null)
            {
                WeiXinCommon.GuanZhuList.Add(new GuanZhuModel()
                {
                    fromUserName = openid,
                    EventKey = ""
                });
            }
        }

C#常用错误全局捕获并记录方法

我从来都不废话 能用代码解决的 绝不说废话 (<_>)

 void Application_Error(object sender, EventArgs e)
    {
        // 在出现未处理的错误时运行的代码
        //在出现未处理的错误时运行的代码  周祥
        Exception ex = Server.GetLastError().GetBaseException();
        StringBuilder str = new StringBuilder();
        str.Append("\r\n" + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"));
        str.Append("\r\n.客户信息:");
        string ip = "";
        if (Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR") != null)
        {
            ip = Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR").ToString().Trim();
        }
        else
        {
            ip = Request.ServerVariables.Get("Remote_Addr").ToString().Trim();
        }
        str.Append("\r\n\tIP:" + ip);
        str.Append("\r\n\t浏览器:" + Request.Browser.Browser.ToString());
        str.Append("\r\n\t浏览器版本:" + Request.Browser.MajorVersion.ToString());
        str.Append("\r\n\t操作系统:" + Request.Browser.Platform.ToString());
        str.Append("\r\n\t访问路径:" + Request.Url.ToString());
        str.Append("\r\n\t请求参数:" + Server.UrlDecode(Request.Form.ToString()));
        str.Append("\r\n.错误信息:" + ex.ToString());
        Log.ErrorLog(str);
       
    }

log.cs 文件下载 错误会存储在根目录 app_data 里面
Log

微信公众号开发 – 获取授权

下面是获取公众号的授权,注意的是 公众号授权与网页授权不一样的 获取到后 缓存起来 保存2小时

string url2 = string.Format(
   "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}",
       WeiXinPay.WxConfig.appid, WeiXinPay.WxConfig.appsecret);
        string returnStr2 = HttpGet.PageGet(url2, null, "text/HTML");
        var obj2 = JsonConvert.DeserializeObject(returnStr2);
        if (obj2 != null && obj2.access_token != "")
        {
            if (PayCenter.getCache("wxModelAccess") != null)
            {
                PayCenter.removeCache("wxModelAccess");
            }
            PayCenter.addCache("wxModelAccess", obj2.access_token, 2);
        }

C# GDI 画文字

其实这种东西 早就会了 只是没东西发了 先拿来滥竽充数

            System.Drawing.Image img = System.Drawing.Image.FromFile(Application.StartupPath + @"\1.png");
            Graphics g = Graphics.FromImage(img);
            FileInfo file = new FileInfo(Application.StartupPath + @"\1.jpg");
            Image img2 = Image.FromFile(file.FullName);
            g.DrawImage(img2, 1910, 480);
            g.Dispose();

C# GDI画图 两张图片合并

好久没发文章了,整点东西上来,废话就不多说了,代码如下:

Bitmap bmp1 = new Bitmap(Application.StartupPath + "\\1.png");
            Bitmap bmp2 = new Bitmap(Application.StartupPath + "\\1.jpg");
            using (Graphics g = Graphics.FromImage(bmp1))
            {
                Size size = new Size(265, 265);
                Rectangle rect = new Rectangle(new Point(bmp1.Width - size.Width - 118, 96), size);
                g.DrawImage(bmp2, rect, new Rectangle(0, 0, bmp2.Width, bmp2.Height), GraphicsUnit.Pixel);
                bmp1.Save(Application.StartupPath + "\\C.jpg");
            }