function handleSubscribe($postObj) { $uid = 0; $params = array(array("" . $postObj->FromUserName, SQLSRV_PARAM_IN), array("" . $postObj->ToUserName, SQLSRV_PARAM_IN), array($uid, SQLSRV_PARAM_INOUT)); $sp = "{call app_subscrible(?,?,?)}"; sp_execute($sp, $params); // //关注时通过微信号获取用户基本信息 if ($user = get_unionid_userinfo(db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"], $postObj->FromUserName)) { $params = array(array("" . $user["openid"], SQLSRV_PARAM_IN), array("" . $user["nickname"], SQLSRV_PARAM_IN), array("" . $user["province"], SQLSRV_PARAM_IN), array("" . $user["city"], SQLSRV_PARAM_IN), array("" . $user["country"], SQLSRV_PARAM_IN), array(intval($user["sex"]), SQLSRV_PARAM_IN), array("" . $user["headimgurl"], SQLSRV_PARAM_IN)); sp_execute("{call app_set_userinfo(?,?,?,?,?,?,?)}", $params); } else { db_log("获取用户信息失败!"); } //用户扫描带场景值二维码 $cids = ""; if (strstr($postObj->EventKey, "qrscene_")) { $cids = substr($postObj->EventKey, strlen("qrscene_")); $cid = str2num(canteenid_content, $cids); } else { $cid = 0; } // $sp = "{call app_user_add_canteen(?,?)}"; $params = array(array($uid, SQLSRV_PARAM_IN), array($cid, SQLSRV_PARAM_IN)); $rs = sp_execute($sp, $params); // response_canteen_welcome($postObj, $cids, $rs[0]["cname"], $rs[0]["picurl"], $rs[0]["newsid"]); }
function handleImage($postObj) { //https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID $access_token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $mediaId = $postObj->MediaId; $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}"; $fileinfo = downloadWeixinFile($url); // $uploadPath = dirname(__FILE__) . "/upload/weixin/"; $tmpFile = time() . ".jpg"; saveWeixinFile($uploadPath . $tmpFile, $fileinfo["body"]); response_text($postObj, "图片上传完成"); }
function handleImage($postObj) { //https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID $access_token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $mediaId = $postObj->MediaId; $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}"; $fileinfo = downloadWeixinFile($url); // $uploadPath = dirname(__FILE__) . "/upload/weixin/"; $fileName = time() . ".jpg"; saveWeixinFile($uploadPath . $fileName, $fileinfo["body"]); response_text($postObj, "图片上传完成"); //保存图片信息 $params = array(array("" . $postObj->FromUserName, SQLSRV_PARAM_IN), array("" . $fileName, SQLSRV_PARAM_IN)); sp_execute("{call app_upload_image(?,?)}", $params); }
/** * 处理关注微信号 * @param $postObj */ function handleSubscribe($postObj) { $sub_scan_flag = 0; $uid = 0; $params = array(array("" . $postObj->FromUserName, SQLSRV_PARAM_IN), array("" . $postObj->ToUserName, SQLSRV_PARAM_IN), array($uid, SQLSRV_PARAM_OUT)); sp_execute("{call app_subscrible(?,?,?)}", $params); //关注时通过微信号获取用户基本信息 if ($user = get_unionid_userinfo(db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"], $postObj->FromUserName)) { $params = array(array("" . $user["openid"], SQLSRV_PARAM_IN), array("" . $user["nickname"], SQLSRV_PARAM_IN), array("" . $user["province"], SQLSRV_PARAM_IN), array("" . $user["city"], SQLSRV_PARAM_IN), array("" . $user["country"], SQLSRV_PARAM_IN), array(intval($user["sex"]), SQLSRV_PARAM_IN), array("" . $user["headimgurl"], SQLSRV_PARAM_IN)); sp_execute("{call app_set_userinfo(?,?,?,?,?,?,?)}", $params); } else { db_log("获取用户信息失败!"); } //用户扫描带场景值二维码 if (strstr($postObj->EventKey, "qrscene_")) { $sub_scan_flag = 1; $scenestr = substr($postObj->EventKey, strlen("qrscene_")); $scenestr = explode("-", $scenestr); $uid_from = str2num(CFG_ID_USER, $scenestr[0]); $cid = str2num(CFG_ID_CAR, $scenestr[1]); log_file("sub, uid_from:{$uid_from}, cid:{$cid}, uid:{$uid}"); //共享车辆 $params = array(array($cid, SQLSRV_PARAM_IN), array($uid_from, SQLSRV_PARAM_IN), array($uid, SQLSRV_PARAM_IN)); sp_execute("{call app_share_car(?,?,?)}", $params); } else { log_file("场景值信息有误"); } if ($sub_scan_flag == 0) { //准备图文消息 $newsContent = array("title" => "您好,欢迎关注金创想!", "description" => "点击查看详情", "picUrl" => CFG_HTTP . "images/jcx0826.png", "url" => CFG_HTTP . "mobile/car_list.php"); response_news($postObj, $newsContent); } else { //查询分享发起人信息 $params = array(array($uid_from, SQLSRV_PARAM_IN), array("", SQLSRV_PARAM_IN)); $rs = sp_execute("{call app_get_userinfo(?,?)}", $params); //准备图文消息 $newsContent = array("title" => "好友" . $rs[0]["nickname"] . "的车辆信息", "description" => "点击查看详情", "picUrl" => CFG_HTTP . CFG_CAR_DEFAULT, "url" => CFG_HTTP . "mobile/car_list.php"); response_news($postObj, $newsContent); } }
if ($_REQUEST["action"] == "finish") { echo '<button id="register" onclick="location.href=\'mycanteen.php\'" class="ui-btn-lg ui-btn-green">点击进入</button>'; } else { echo '<button id="register" onclick="toRegister()" class="ui-btn-lg ui-btn-primary">立即注册</button>'; } ?> </div> </div> </div> </div> <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> <script> <?php //通过access_token获取jsapi_ticket $ticket = db_get_token_ticket(CFG_APPID, CFG_SECRET)["ticket"]; $signPackage = get_sign_package(CFG_APPID, $ticket); ?> wx.config({ debug: false, appId: '<?php echo $signPackage["appId"]; ?> ', timestamp: <?php echo $signPackage["timestamp"]; ?> , nonceStr: '<?php echo $signPackage["nonceStr"]; ?>
require_once "../config.php"; require_once "../conn.php"; require_once "../include/php_funs.php"; require_once "../db_weixin_funs.php"; require_once "admin_filter.php"; //检查权限 if (!filter_canteenadmin()) { exit; } $cid = str2num(canteenid_content, $_REQUEST["cids"]); $verurl = $_REQUEST["verurl"]; if ($verurl == "") { /* 根据餐厅编号生成带场景二维码 */ //餐厅编号 $str = num2str(canteenid_content, $cid); $token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$token}"; /* * 永久二维码请求说明 * http请求方式: POST * URL: https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN * POST数据格式:json * POST数据例子:{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}} * 或者也可以使用以下POST数据创建字符串形式的二维码参数: * {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}} */ $data = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_id":234, "scene_str":"' . $str . '"}}}'; $data = json_decode(get_http_result($url, $data), true); // //插入数据库,更新餐厅二维码信息 $sp = "{call web_set_canteen_verurl(?,?)}";
/** * 将餐厅信息设置到session中 * @param $row */ function set_canteen_session($row) { $_SESSION["cid"] = $row["cid"]; $_SESSION["cname"] = $row["cname"]; $_SESSION["verticket"] = $row["verticket"]; $_SESSION["verurl"] = $row["verurl"]; $_SESSION["allow"] = $row["allow"]; $_SESSION["cpicurl"] = $row["picurl"]; $_SESSION["ctelnum"] = $row["telnum"]; $_SESSION["roleid"] = $row["roleid"]; //判断餐厅是否有二维码,没有则创建生成二维码 if (strlen($row["verticket"]) < 1) { /* 根据餐厅编号生成带场景二维码 */ $str = num2str(canteenid_content, $_SESSION["cid"]); $token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$token}"; $data = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_id":234, "scene_str":"' . $str . '"}}}'; $data = json_decode(get_http_result($url, $data), true); //插入数据库,更新餐厅二维码信息 $params = array(array(intval($_SESSION["cid"]), SQLSRV_PARAM_IN), array("" . $data["ticket"], SQLSRV_PARAM_IN), array("" . $data["url"], SQLSRV_PARAM_IN), array("", SQLSRV_PARAM_IN)); sp_execute("{call web_set_canteen_verify(?,?,?,?)}", $params); $_SESSION["verticket"] = $data["ticket"]; } }
/** * 餐厅管理人员受理订单后,发送消息给用户 * 取餐通知 * 格式: * 商店名称 * 订单编号 * 订单类型 * 付款状态 * @param $cids 餐厅编号 * @param $oid 订单编号 * @param $uname 用户姓名 * @param $cname 餐厅名称 * @param $winname 窗口名称 * @param $paysta 支付状态 * @param $uid 用户编号 * @param $amount 菜品数量 * @param $total 总价 * @param $towid 接收消息的微信号 */ function altermsg_for_sales($cids, $oid, $uname, $cname, $winname, $paysta, $uid, $amount, $total, $towid) { $token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $oids = num2str_x(orderid_content_x, $oid); $uids = num2str(userid_content, $uid); $pre_str = '{"first": {"value":"%s,在【%s】取餐","color":"#000000"},"storeName":{"value":"%s","color":"#000000"},"orderId":{"value": "%s","color":"#000000"},"orderType":{"value":"默认","color":"#000000"},"remark":{"value":"订单数量:%s\\r\\n订单金额:¥%0.2f\\r\\n付款状态:%s\\r\\n\\r\\n点击查看订单详情,并完成销售","color":"#000000"}}'; $data = sprintf($pre_str, $uname, $winname, $cname, $oids, $amount, $total, $paysta); send_template_message($token, $towid, CFG_TPMSG_QUCAN, CFG_HTTP . "mobile/admin_order_list.php?act=preuids&cids={$cids}&uids={$uids}", "#7B68EE", $data); }
<?php require_once "config.php"; require_once "db_weixin_funs.php"; // $ret = weixin_create_menu(db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"], dirname(__FILE__) . "/wxp_menu.json"); if ($ret) { echo $ret; }