Browse Source

增加简单密码功能

shileiye 8 years ago
parent
commit
e09da6b2ad
3 changed files with 953 additions and 21 deletions
  1. 883 0
      data/tiaodaoAPI.md
  2. 45 6
      index.php
  3. 25 15
      ok.php

+ 883 - 0
data/tiaodaoAPI.md

@@ -0,0 +1,883 @@
+[TOCM]
+
+[TOC]
+
+##商品评论提交API
+
+POST `/product/product/write`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+|recommend|是|0=自由讨论,1=推荐理由,2=专业点评|
+|review_input_image[]|否|评论图片地址数组|
+|text|是|评论内容|
+|re_review_id|是|上级评论ID,顶级=0,recommend=0时可用|
+|good|是|商品优点(recommend=2时必填)|
+|defect|是|商品缺点(recommend=2时必填)|
+|price|是|购买价格(recommend=2时必填)|
+|channel|是|购买渠道(recommend=2时必填)|
+|model|是|购买型号(recommend=2时必填)|
+成功返回:success
+```js
+{
+  "success": "您的评论已经提交,请等待管理员审核!",
+  "data": {
+    "product_id":"69",
+    "text":"综合评价",
+    "good":"商品优点",
+    "defect":"商品缺点",
+    "price":"购买价格",
+    "channel":"购买渠道",
+    "model":"购买型号",
+    "customer_id": 19,
+    "review_id": 3,
+	"re_review_id": 3,
+	"date_added": "2016-01-22 15:36:58",
+	"recommend": "2",
+    "author": {
+      "name": "sly",
+      "avatar": "http://xxx.xxx.xxx/xxx.jpg"
+    }
+  }
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##商品综合评分获取API
+
+POST `/product/product/ratings`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+
+成功返回:success
+```js
+{
+  "success": "获取成功",
+  "data": {
+    "rating": "4.7",
+    "total": 3,
+    "ratings": {
+      "rating1": 0,
+      "rating2": 0,
+      "rating3": 0,
+      "rating4": 1,
+      "rating5": 2
+    }
+  }
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##评论点赞API
+
+POST `/product/product/replyup`
+
+|参数|必需|描述|
+|---|---|---|
+|review_id|是|评论ID|
+
+成功返回:success
+```js
+{
+  "success": "点赞成功",
+  "data": {
+    "review_id": "2",
+    "upnum": 2
+  }
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "你已经点过赞"
+}
+```
+##商品点赞API
+
+POST `/product/product/productup`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+
+成功返回:success
+```js
+{
+  "success": "点赞成功",
+  "data": {
+    "product_id": "2",
+    "upnum": 2
+  }
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "你已经点过赞"
+}
+```
+  
+##用户收藏列表API
+
+POST `/account/wishlist/wishlist`
+
+|参数|必需|描述|
+|---|---|---|
+|page|否|第几页,默认=1|
+|limi|否|每页显示多少条记录,默认=12|
+  
+
+成功返回:success
+```js
+{
+  "success": "成功获取收藏列表",
+  "total": 2,
+  "pages": 2,
+  "data": [
+    {
+      "product_id": "40",
+      "thumb": "http://localhost/image/cache/catalog/demo/40_1-47x47.jpg",
+      "name": "苹果iPhone 6 Plus",
+      "model": "product 11",
+      "up": "0",
+      "price": "¥123.20",
+      "href": "http://localhost/index.php?route=product/product&product_id=40"
+    },
+    {
+      "product_id": "44",
+      "thumb": "http://localhost/image/cache/catalog/demo/44_1-47x47.jpg",
+      "name": "MacBook Air",
+      "model": "Product 17",
+      "up": "1",
+      "price": "¥1,202.00",
+      "href": "http://localhost/index.php?route=product/product&product_id=44"
+    }
+  ]
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "你还没有登录系统"
+}
+```
+
+##添加收藏API
+
+POST `/account/wishlist/add`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+
+成功返回:success
+```js
+{
+  "success": "收藏成功!",
+  "total": "6"
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+  
+##删除收藏API
+
+POST `/account/wishlist/del`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+
+成功返回:success
+```js
+{
+  "success": "成功删除收藏",
+  "total": "5"
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##用户中心评论列表API
+
+POST `/account/review/reviewlist`
+
+|参数|必需|描述|
+|---|---|---|
+|page|否|第几页,默认=1|
+|limi|否|每页显示多少条记录,默认=12|
+|what|否|0=自由讨论,1=推荐理由,2=专业点评,默认=0|
+  
+
+成功返回:success
+```js
+{
+  "success": "成功获取点评列表",
+  "total": 3,
+  "pages": 1,
+  "data": [
+    {
+      "product_id": 47,
+      "pname": "HP LP3065",
+      "text": "一个讨论回复一个讨论回复一个讨论回复一个讨论回复",
+      "good": null,
+      "defect": null,
+      "model": "",
+      "price": "¥0.00",
+      "channel": "",
+      "rating": 0,
+      "date_added": "2016-01-18 15:55:55",
+      "href": "http://localhost/index.php?route=product/product&product_id=47"
+    },
+    {
+      "product_id": 47,
+      "pname": "HP LP3065",
+      "text": "个讨论这个是一个讨论回复一个讨论回复一个讨论回复一个讨论回复一个讨论回复一个讨论回复一个讨论回复",
+      "good": null,
+      "defect": null,
+      "model": "",
+      "price": "¥0.00",
+      "channel": "",
+      "rating": 0,
+      "date_added": "2016-01-18 15:55:52",
+      "href": "http://localhost/index.php?route=product/product&product_id=47"
+    },
+    {
+      "product_id": 47,
+      "pname": "HP LP3065",
+      "text": "个讨论这个是一个讨论这个是一个讨论个讨论这个是一个讨论这个是一个讨论个讨论这个是一个讨论这个是一个讨论个讨论这个是一个讨论这个是一个讨论个讨论这个是一个讨论这个是一个讨论",
+      "good": null,
+      "defect": null,
+      "model": "",
+      "price": "¥0.00",
+      "channel": "",
+      "rating": 0,
+      "date_added": "2016-01-18 15:55:35",
+      "href": "http://localhost/index.php?route=product/product&product_id=47"
+    }
+  ]
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "你还没有登录系统"
+}
+```
+
+##用户中心消息列表API
+
+POST `/account/message/message`
+
+|参数|必需|描述|
+|---|---|---|
+|page|否|第几页,默认=1|
+|limi|否|每页显示多少条记录,默认=12|
+|type|否|0=系统消息,1=用户私信,默认=0|
+|status|否|all=全部消息,0=未读消息,1=已读消息,默认=all|
+  
+
+成功返回:success
+```js
+{
+  "success": "成功获取消息列表",
+  "total": 5,
+  "not_read_total": 4,
+  "pages": 3,
+  "data": [
+    {
+      "message_id": 2,
+      "customer_id": 20,
+      "uname": "egoist",
+      "type": 1,
+      "to_customer_id": 19,
+      "status": 0,
+      "title": "测试消息标题1",
+      "description": "测试消息内容1",
+      "date_added": "2016-01-20 11:39:47"
+    },
+    {
+      "message_id": 3,
+      "customer_id": 20,
+      "uname": "egoist",
+      "type": 1,
+      "to_customer_id": 19,
+      "status": 0,
+      "title": "测试消息标题2",
+      "description": "测试消息内容2",
+      "date_added": "2016-01-20 11:39:47"
+    }
+  ]
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "你还没有登录系统"
+}
+```
+
+##消息发送API
+
+POST `/account/message/add`
+
+|参数|必需|描述|
+|---|---|---|
+|to_customer_id|是|接收者ID|
+|title|是|私信标题|
+|description|是|私信内容|
+
+成功返回:success
+```js
+{
+  "success": "消息发送成功!",
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##消息删除API
+
+POST `/account/message/del`
+
+|参数|必需|描述|
+|---|---|---|
+|message_id|是|消息ID,为0则全部删除|
+
+成功返回:success
+```js
+{
+  "success": "成功删除消息",
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##消息标记已读API
+
+POST `/account/message/status`
+
+|参数|必需|描述|
+|---|---|---|
+|message_id|是|消息ID,为0则全部标记为已读|
+
+成功返回:success
+```js
+{
+  "success": "成功标记为已读",
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##获取商品历史价格API
+
+POST `/product/product/productprice`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+|num|否|调取记录数量,默认=90|
+
+成功返回:success
+```js
+{
+  "success": "获取历史价格成功",
+  "data": [
+    {
+      "id": 147,
+      "mall": "1号店",
+      "price": "52.00",
+      "created_at": "2016-01-17"
+    },
+    {
+      "id": 146,
+      "mall": "京东商城",
+      "price": "52.00",
+      "created_at": "2016-01-16"
+    }
+  ]
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+**首页获取商品列表API:**
+
+POST `common/home/productlist`
+
+|参数|必需|描述|
+|---|---|---|
+|type|否|调用商品类型,默认=product_id (product_id=最新商品,rating=评分最多,wishlists=关注最多)|
+|page|否|第几页,默认=1|
+|limi|否|每页显示多少条记录,默认=7|
+
+成功返回:success
+```js
+{
+  "success": "成功获取商品列表",
+  "total": 262,
+  "pages": 38,
+  "data": [
+    {
+      "product_id": "343",
+      "thumb": null,
+      "name": "ZMI 10000毫安 移动电源/充电宝 聚合物 紫米电子 PB810 ",
+      "text": "ZMI的厂家是负责小米移动电源设计,研发,生产的一个厂家,所以ZMI移动电源的质量是十分可靠的。这款ZMI移动电源是一款颜值很高的移动电源,外观去繁留简,一股小清新气息,充电速度和转化率都十分不错,有..",
+      "author": "挑到网小编",
+      "recommend_avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "price": "¥99.00",
+      "up": "0",
+      "rating": "0.0000",
+      "href": "http://localhost:8000/index.php?route=product/product&product_id=343",
+      "date_added": "2016-02-01",
+      "wishlists": "0"
+    },
+    {
+      "product_id": "342",
+      "thumb": null,
+      "name": "摩托罗拉A8 商用对讲机",
+      "text": "自驾游,探险,物业,大型商城必不可少的对讲机,五公里以内对讲没有问题,产品轻巧易用,话音清晰,坚固耐用,并且符合美国军用标准。运用了先进的X-PAND音频技术以及摩托罗拉的语音与低电平扩展技术,可以实..",
+      "author": "挑到网小编",
+      "recommend_avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "price": "¥680.00",
+      "up": "0",
+      "rating": "0.0000",
+      "href": "http://localhost:8000/index.php?route=product/product&product_id=342",
+      "date_added": "2016-02-01",
+      "wishlists": "0"
+    }
+  ]
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "参数错误"
+}
+```
+
+##分类获取商品列表API
+
+GET `api/category/productlist`
+
+|参数|必需|描述|
+|---|---|---|
+|path|是|分类ID|
+|page|否|第几页,默认=1|
+|limit|否|每页显示多少条记录,默认=15|
+|sort|否|排序字段名,为空ID倒序,默认空=ID,关注度=wishlists,评分=rating,价格=p.price|
+|order|否|与sort配合用,顺序=ASC,倒序=DESC|
+|spare|否|商品类别,推荐=0(默认),备选=1|
+|brands|否|品牌ID,默认全部,可多选|
+|filter|否|筛选条件ID,默认全部,可多选|
+|minPrice|否|最低价格筛选数值,为空则不限制|
+|maxPrice|否|最高价格筛选数值,为空则不限制|
+
+成功返回:success
+```js
+{
+  "success": "成功获取商品列表",
+  "breadcrumbs": [
+    {
+      "path_id": "127_1203_1204",
+      "text": "手机",
+      "href": "http://localhost:8000/index.php?route=api/category/productlist&path=127_1203_1204"
+    }
+  ],
+  "manufacturers": [
+    {
+      "manufacturer_id": "241",
+      "name": " 优加",
+      "image": ""
+    },
+    {
+      "manufacturer_id": "254",
+      "name": " 三星(SAMSUNG)",
+      "image": ""
+    }
+  ],
+  "filters": [
+    {
+      "fgid": "1",
+      "dname": "手机系统",
+      "description": "操作系统(Operating System,简称OS)。",
+      "type": [
+        {
+          "fid": "1",
+          "href": "http://localhost:8000/index.php?route=api/category/productlist&path=127_1203_1204&filter=1",
+          "xname": "WP"
+        },
+        {
+          "fid": "2",
+          "href": "http://localhost:8000/index.php?route=api/category/productlist&path=127_1203_1204&filter=2",
+          "xname": "安卓"
+        },
+        {
+          "fid": "3",
+          "href": "http://localhost:8000/index.php?route=api/category/productlist&path=127_1203_1204&filter=3",
+          "xname": "苹果"
+        }
+      ]
+    }
+  ],
+  "products": [
+    {
+      "product_id": "341",
+      "thumb": "http://localhost:8000/image/cache/placeholder-200x200.png",
+      "name": "三星 Galaxy S6 edge(G9250)32G版 松珀绿 移动联通电信4G手机",
+      "description": " ..",
+      "text": "三星的S6 edge一上市的时候我的朋友就入手了,当时价格是6088元..",
+      "recommend_author": "挑到网小编",
+      "recommend_avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "price": "¥4,388.00元",
+      "up": 0,
+      "special": false,
+      "tax": "¥4,388.00元",
+      "minimum": "1",
+      "rating": 0,
+      "href": "http://localhost:8000/index.php?route=product/product&path=127_1203_1204&product_id=341",
+      "wishlists": 0
+    },
+    {
+      "product_id": "130",
+      "thumb": null,
+      "name": "三星(SAMSUNG) UA55JU6800JXXZ 55英寸 曲面 超高清4K 无线wifi LED液晶电视",
+      "description": " ..",
+      "text": "最近几年是液晶电视飞速发展的几年,除了不断提升的分辨率55..",
+      "recommend_author": "挑到网小编",
+      "recommend_avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "price": "¥7,999.00元",
+      "up": 0,
+      "special": false,
+      "tax": "¥7,999.00元",
+      "minimum": "1",
+      "rating": 0,
+      "href": "http://localhost:8000/index.php?route=product/product&path=127_1203_1204&product_id=130",
+      "wishlists": 0
+    }
+  ],
+  "filter_data": {
+    "filter_category_id": 1204,
+    "filter_filter": "",
+    "manufacturer_id": "",
+    "sort": "p.product_id",
+    "order": "DESC",
+    "start": 0,
+    "limit": 15,
+    "spare": 0,
+    "minPrice": 0,
+    "maxPrice": 0
+  },
+  "product_total": 2,
+  "page": 1,
+  "page_total": 1
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "分类不存在!"
+}
+```
+
+##获取商品信息API
+
+GET `api/product/info`
+
+|参数|必需|描述|
+|---|---|---|
+|product_id|是|商品ID|
+|path|否|分类ID,可使用"_"连接|
+
+成功返回:success
+```js
+{
+  "success": "成功获取商品信息",
+  "breadcrumbs": [
+    {
+      "path_id": "395",
+      "text": "个护化妆、清洁用品"
+    },
+    {
+      "path_id": "395_396",
+      "text": "清洁用品"
+    },
+    {
+      "path_id": "395_396_399",
+      "text": "清洁工具"
+    }
+  ],
+  "product_mall_prices": [
+    {
+      "mall_id": "1",
+      "mallname": "京东商城",
+      "url": "http://item.jd.com/1269538.html",
+      "description": "",
+      "price": "89.00",
+      "created_at": "2016-02-26"
+    }
+  ],
+  "product_reasons": [
+    {
+      "review_id": "520",
+      "uname": "sly",
+      "avatar": "https://secure.gravatar.com/avatar/6c95be464acef4719a7176dc39aee9ff?s=80&d=mm&r=g",
+      "customer_id": "19",
+      "text": "推荐理由1",
+      "sort_order": "0",
+      "date_added": "2016-01-22"
+    },
+    {
+      "review_id": "747",
+      "uname": "挑到网小编",
+      "avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "customer_id": "13396",
+      "text": "推荐理由2",
+      "sort_order": "0",
+      "date_added": "2016-01-28"
+    }
+  ],
+  "product_id": 69,
+  "liked": false,
+  "favorite": false,
+  "up": "1",
+  "market_price": "0.00",
+  "heading_title": "3M思高 W4胶棉拖把 全能蝶彩胶棉拖",
+  "meta_title": "3M思高 W4胶棉拖把 全能蝶彩胶棉拖",
+  "tab_review": "12",
+  "manufacturer": "3M",
+  "model": "",
+  "reward": null,
+  "points": "0",
+  "description": "商品详情描述",
+  "popup": null,
+  "image": null,
+  "thumb": null,
+  "images": [
+    {
+      "image": null,
+      "popup": null,
+      "thumb": null
+    },
+    {
+      "image": null,
+      "popup": null,
+      "thumb": null
+    },
+    {
+      "image": null,
+      "popup": null,
+      "thumb": null
+    },
+    {
+      "image": null,
+      "popup": null,
+      "thumb": null
+    }
+  ],
+  "price": "¥69.00元",
+  "special": false,
+  "tax": "¥69.00元",
+  "discounts": [],
+  "minimum": "1",
+  "review_status": "1",
+  "review_guest": true,
+  "customer_name": "",
+  "reviews": "12 评论",
+  "rating": 2,
+  "attribute_groups": [],
+  "products": [],
+  "tags": [],
+  "recurrings": []
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "未发现该商品!"
+}
+```
+
+##前台文件上传API
+
+POST `common/filemanager/upload`
+
+|参数|必需|描述|
+|---|---|---|
+|file|是|文件地址|
+
+成功返回:success
+```js
+{
+  "success": "成功: 文件已经上传!",
+  "image": "catalog/review/20160405/paobu.jpg",
+  "thumb": "http://localhost:8000/image/cache/catalog/review/20160405/paobu-100x100.jpg"
+}
+```
+
+失败返回:error
+```js
+{
+  "error": "请登录后再操作!"
+}
+```
+
+##搜索商品列表API
+
+GET `api/search`
+
+|参数|必需|描述|
+|---|---|---|
+|search|是|搜索关键词|
+|page|否|第几页,默认=1|
+|category_id|否|搜索的分类ID,默认=0|
+|limit|否|每页显示多少条记录,默认=15|
+|sort|否|排序字段名,为空ID倒序,默认空=p.sort_order,关注度=wishlists,评分=rating,价格=p.price|
+|order|否|与sort配合用,顺序=ASC,倒序=DESC|
+|minPrice|否|最低价格筛选数值,为空则不限制|
+|maxPrice|否|最高价格筛选数值,为空则不限制|
+
+成功返回相应数据数据
+```js
+{
+  "heading_title": "搜索 - 手机",
+  "filter_data": {
+    "filter_name": "手机",
+    "filter_tag": "手机",
+    "filter_description": "",
+    "filter_category_id": 0,
+    "filter_sub_category": "",
+    "sort": "p.sort_order",
+    "order": "ASC",
+    "start": 0,
+    "limit": "15"
+  },
+  "categories": [
+    {
+      "category_id": "1204",
+      "name": "手机"
+    },
+    {
+      "category_id": "127",
+      "name": "手机数码、智能设备"
+    }
+  ],
+  "products": [
+    {
+      "product_id": "341",
+      "up": "0",
+      "thumb": "http://localhost:8000/image/cache/placeholder-200x200.png",
+      "name": "三星 Galaxy S6 edge(G9250)32G版 松珀绿 移动联通电信4G手机",
+      "description": " ..",
+      "recommend": "三星的S6 edge一上市的时候我的朋友就入手了..",
+      "recommend_author": "挑到网小编",
+      "recommend_avatar": "https://secure.gravatar.com/avatar/855cd3f3156c2d717499681d03604867?s=80&d=mm&r=g",
+      "price": "¥4,388.00元",
+      "special": false,
+      "tax": "¥4,388.00元",
+      "minimum": "1",
+      "rating": 0,
+      "reviews": 0,
+      "href": "http://localhost:8000/index.php?route=product/product&product_id=341",
+      "wishlists": "0"
+    }
+  ],
+  "product_total": 1,
+  "page_total": 1,
+  "page": 1,
+  "search": "手机",
+  "description": "",
+  "category_id": 0,
+  "sub_category": "",
+  "sort": "p.sort_order",
+  "order": "ASC",
+  "limit": "15"
+}
+```
+
+分类和商品无数据返回空数组
+```js
+{
+  "categories": [],
+  "products": []
+}
+```
+
+##用户信息API
+
+GET `api/customer/info`
+
+成功返回:success
+```js
+{
+    "success":"成功获取账户信息",
+    "data":{
+        "customer_id":"19",
+        "fullname":"sly",
+        "avatar":"https://www.shileiye.com/wp-content/uploads/2015/11/ADSafe-Android.png",
+        "email":"shileiye@qq.com",
+        "ip":"::1"
+    }
+}
+```
+
+失败返回:error
+```js
+{
+    error: "请登录后再试!"
+}
+```

+ 45 - 6
index.php

@@ -39,7 +39,7 @@ $title = "MD记事本";
         saveHTMLToTextarea: true, // 保存 HTML 到 Textarea
         searchReplace: true,
         //watch : false,                // 关闭实时预览
-        htmlDecode: "style,script,iframe|on*", // 开启 HTML 标签解析,为了安全性,默认不开启    
+        htmlDecode: "style,script,iframe|on*", // 开启 HTML 标签解析,为了安全性,默认不开启
         //toolbar  : false,             //关闭工具栏
         //previewCodeHighlight : false, // 关闭预览 HTML 的代码块高亮,默认开启
         emoji: true,
@@ -87,14 +87,16 @@ $title = "MD记事本";
            */
           Save: function () {
             if (md == "new.md") {
+              ispass();
               var FileName = prompt('请输入文件名');
+
               if (FileName) {
                 var aj = $.ajax({
                   url: 'ok.php',
-                  data: 'm=newfile&md=<?php echo $dir; ?>' + FileName + '.md&data=' + MDEditor.getMarkdown(),
                   type: 'post',
                   cache: false,
                   dataType: 'json',
+                  data: {'m': 'newfile', 'md': '<?php echo $dir; ?>' + FileName + '.md', 'data': MDEditor.getMarkdown(), 'pass': getCookie('pass')},
                   success: function (data) {
                     if (data.msg == "true") {
                       md = FileName + ".md";
@@ -110,12 +112,14 @@ $title = "MD记事本";
                 });
               }
             } else {
+              ispass();
               var aj = $.ajax({
                 url: 'ok.php',
-                data: 'm=savefile&md=<?php echo $dir; ?>' + md + '&data=' + MDEditor.getMarkdown(),
                 type: 'post',
                 cache: false,
                 dataType: 'json',
+                data: {'m': 'savefile', 'md': '<?php echo $dir; ?>' + md, 'data': MDEditor.getMarkdown(), 'pass': getCookie('pass')},
+                //{ 'option':'delete','name':'11&adb'},
                 success: function (data) {
                   if (data.msg == "true") {
                     $("title").html(md + " - " + title);
@@ -132,14 +136,15 @@ $title = "MD记事本";
             }
           },
           File: function () {
+            ispass();
             var FileName = prompt('请输入文件名');
             if (FileName) {
               var aj = $.ajax({
-                url: 'ok.php', // 跳转到 action  
-                data: 'm=newfile&md=<?php echo $dir; ?>' + FileName + '.md&data=NewFile',
+                url: 'ok.php', // 跳转到 action
                 type: 'post',
                 cache: false,
                 dataType: 'json',
+                data: {'m': 'newfile', 'md': '<?php echo $dir; ?>' + FileName + '.md', 'data': MDEditor.getMarkdown(), 'pass': getCookie('pass')},
                 success: function (data) {
                   if (data.msg == "true") {
                     MDEditor.setValue("");
@@ -181,7 +186,7 @@ $title = "MD记事本";
             "Ctrl-O": function (cm) {
               alert("Ctrl-O未启用");
             }
-			,
+            ,
             "Alt-N": function (cm) {
               alert("Alt-N未启用");
             }
@@ -202,6 +207,40 @@ $title = "MD记事本";
 
       });
     });
+    function getCookie(c_name)
+    {
+      if (document.cookie.length > 0)
+      {
+        c_start = document.cookie.indexOf(c_name + "=")
+        if (c_start != -1)
+        {
+          c_start = c_start + c_name.length + 1
+          c_end = document.cookie.indexOf(";", c_start)
+          if (c_end == -1)
+            c_end = document.cookie.length
+          return unescape(document.cookie.substring(c_start, c_end))
+        }
+      }
+      return ""
+    }
+
+    function setCookie(c_name, value, expiredays)
+    {
+      var exdate = new Date()
+      exdate.setDate(exdate.getDate() + expiredays)
+      document.cookie = c_name + "=" + escape(value) +
+              ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
+    }
+    function ispass()
+    {
+      pass = getCookie('pass');
+      if (pass == null || pass == "") {
+        var pa = prompt('请输入密码');
+        if (pa) {
+          setCookie('pass', pa, 365);
+        }
+      }
+    }
 	</script>
   </body>
 </html>

+ 25 - 15
ok.php

@@ -1,26 +1,36 @@
 <?php
+session_start();
 header('Content-type:application/json;charset=UTF-8');
 $m = @$_POST["m"];
 $md = @$_POST["md"];
 $body = @$_POST["data"];
-if ($m == "newfile") {
-	if (!is_file($md)) {
-		$nf = file_put_contents($md, $body);
-		if ($nf) {
+$pass = @$_POST["pass"];
+if((int)$pass == 860712){
+	if ($m == "newfile") {
+		if (!is_file($md)) {
+			$nf = file_put_contents($md, $body);
+			if ($nf) {
+				$msg["msg"] = "true";
+			} else {
+				$msg["msg"] = "新建文件出现错误,请重试!";
+			}
+		} else {
+			$msg["msg"] = "文件已存在,请重新命名!";
+		}
+	} else if ($m == "savefile") {
+		$sf = file_put_contents($md, $body);
+		//$sf = fopen($md, 'w+');
+		if ($sf) {
+			//fwrite($sf, $body);
 			$msg["msg"] = "true";
 		} else {
-			$msg["msg"] = "新建文件出现错误,请重试!";
+			$msg["msg"] = "保存文件出现错误,请重试!";
 		}
-	} else {
-		$msg["msg"] = "文件已存在,请重新命名!";
-	}
-} else if ($m == "savefile") {
-	$sf = file_put_contents($md, $body);
-	if ($sf) {
-		$msg["msg"] = "true";
-	} else {
-		$msg["msg"] = "保存文件出现错误,请重试!";
+		//fclose($sf);
 	}
+} else {
+	$msg["msg"] = "操作失败,密码错误!(MD记事本尚未完工,暂不对外开放)";
+	setcookie('pass', NULL);
 }
-$msg["post"] = $_POST;
+//$msg["post"] = $_POST;
 echo json_encode($msg);