function onBridgeReady() {
WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
nodejs 常用插件
使用会话:
1.安装express-session中间件
npm install express-session
2.安装cookie-parser中间件
npm install cookie-parser
3.注册后台(app.js)
var session = require('express-session'); var cookieParser = require('cookie-parser'); app.use(cookieParser()); app.use(session({ secret: 'zhouxiangblog', resave: true, saveUninitialized: false }));
4.写入session
req.session.userinfo = userinfo;
5.读取session
req.session.userinfo
GZIP压缩:
1.安装compression
npm install compression
2.在APP.JS里 var app = express(); 该位置下面 添加如下代码即可
var compression = require('compression'); app.use(compression());
这样就完成了nodejs开启GZIP压缩的功能
缓存:
1.安装memory-cache
npm install memory-cache
2.调用方法
var cache = require('memory-cache');// now just use the cachecache.put('foo', 'bar'); console.log(cache.get('foo'))// that wasn't too interesting, here's the good part cache.put('houdini', 'disappear', 100) // Time in msconsole.log('Houdini will now ' + cache.get('houdini')); setTimeout(function() { console.log('Houdini is ' + cache.get('houdini')); }, 200);
nodejs 连接数据库
nodejs 创建项目
1.https://nodejs.org/en/download/ 下载nodejs 安装
2.npm安装express插件。
npm install express
3.安装express命令工具 npm install -g express-generator
3.express 安装nodejs项目。
express -e ejs MyApp
4.进入项目目录,安装nodejs依赖模块.
cd MyApp && npm install
5.安装代码修改自动重启
npm install -g nodemon
6.启动项目 cd MyApp 然后调用 nodemon server.js
ionic2实现cordova打印
基于KT50机器,E488打印机器实现,基于语言angular2和cordova,使用regoPrinter.jar完成。
插件下载: cordova-plugin-KTPrint
安装至目录
然后单独封装js部分,我目前是修改ionic-native插件(懒):
ionic-native\dist\es5\plugins --增加文件 KTPrint.d.zip 解压缩 ionic-native\dist\es5 --替换文件 index.d.zip 解压缩 ionic-native\dist\esm\plugins --增加文件 KTPrint.js.zip ionic-native\dist\esm --替换文件 index.d2.zip 解压缩
替换完成后,在项目调用KTPrint 调用打印即可 :
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { KTPrint } from 'ionic-native'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { constructor(public navCtrl: NavController) { } //打印测试 PrintTest() { try { KTPrint.Print("测试周祥"); } catch (e) { alert(e); } } }
到此,基本完成,不明白加Q咨询,效果如下:
以上方法需对应机型,如果增加删除其他方法,参考打印机文档修改即可!
打印机文档(E488):2017_4_10_17_44_13_147_1007
C#操作EXCEL以及生成公司公章
最近项目需求 做了个小工具 操作EXCEL以及生成公司公章
TestOnSeal _top = new TestOnSeal(); _top.TextFont = new System.Drawing.Font("黑体", 16, FontStyle.Bold); _top.FillColor = Color.Red; //_top.ColorTOP = Color.Black; _top.Text = comname; _top.BaseString = ""; _top.ShowPath = true; _top.LetterSpace = 1; _top.SealSize = 180; _top.CharDirection = Char_Direction.Center; _top.SetIndent(20); Graphics g = this.CreateGraphics(); g.DrawImage(_top.TextOnPathBitmap(), 0, 0); _top.CharDirection = Char_Direction.ClockWise; g.DrawImage(_top.TextOnPathBitmap(), 180, 0); _top.CharDirection = Char_Direction.AntiClockWise; g.DrawImage(_top.TextOnPathBitmap(), 0, 180); _top.SetIndent(20); _top.CharDirection = Char_Direction.Center; g.DrawImage(_top.TextOnPathBitmap(), 180, 180); _top.TextOnPathBitmap().Save(System.Windows.Forms.Application.StartupPath + "/tp/" + comname + ".png", System.Drawing.Imaging.ImageFormat.Png); g.Dispose();
微信公众号开发 – 获取所有关注的用户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 Listopenid { 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();