wxid; $wxopenid = $postjson->wxopenid; $subscribekey = $postjson->subscribekey; mlog($postStr, 'get_subscribe_key/'.$wxid); $wechat = M('wx_user')->where('wxid', $wxid)->find(); //更新openid关注状态 if ($wechat) { $userdata['wxid'] = $wxid; $userdata['issubscribe'] = 1; $userdata['subscribe_date'] = time(); if (strpos($subscribekey, 'last_trade_no') !== false) { $subscribekey = ""; } $userdata['staffno'] = $subscribekey; $openlist = M('wx_openlist')->where(array('store_id' => $wechat['store_id'], 'wxopenid' => $wxopenid))->find(); if ($openlist) { M('wx_openlist')->where(array('store_id' => $wechat['store_id'], 'wxopenid' => $wxopenid))->save($userdata); } else { $userdata['store_id'] = $wechat['store_id']; $userdata['wxopenid'] = $wxopenid; M('wx_openlist')->add($userdata); } } $keyword = M('wx_menu')->where(array('store_id' => $wechat['store_id'], 'gzstate' => 1))->find(); mlog(json_encode($keyword), 'Wechat/'.$wxid); return json_encode($keyword); } //取消关注时获取关键字api public function unsubscribe() { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; $postjson = json_decode($postStr); $wxid = $postjson->wxid; $wxopenid = $postjson->wxopenid; mlog($postStr, 'unsubscribe/'.$wxid); $wechat = M('wx_user')->where('wxid', $wxid)->find(); //更新openid关注状态 if ($wechat) { $userdata['issubscribe'] = 0; $userdata['unsubscribe_date'] = time(); M('wx_openlist')->where(array('store_id' => $wechat['store_id'], 'wxopenid' => $wxopenid))->save($userdata); } } //取消授权触发修改数据库状态api public function unauthorized() { $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; mlog($postStr, 'unauthorized'); $postjson = json_decode($postStr); $appid = $postjson->appid; mlog($appid, 'unauthorized'); $data["wxstate"] = 0; $data["wait_access"] = 0; // upload_ylp_log('取消授权'); $re = M('wx_user')->where(array('appid' => $appid))->save($data); return json_encode($re); } public function dow($re, $lo) { return Http::curl_download($re, "./" . $lo); } //消息回复信息查询接口 public function reply() { $str = file_get_contents("php://input"); //$str="{\"key\":\"\u6587\u5b57\u56de\u590d\",\"wxid\":\"gh_b36af13841a6\",\"inputtype\":1}"; $postjson = json_decode($str); $wxid = $postjson->wxid; $key = $postjson->key; $inputtype = $postjson->inputtype; mlog("菜单值:" . $str, "reply/".$wxid); $wechat = M('wx_user')->where('wxid', $wxid)->find(); if (empty($inputtype)) { $map['id'] = $key; $keyrow = M('wx_menu')->where(array('store_id' => $wechat['store_id'], 'token' => $wechat['token']))->where($map)->find(); } else { //$keyrow = M('wx_keyrepay')->where(array('store_id' => $wechat['store_id'], 'keyword' => $key, 'isshow' => 1))->limit(1)->order('id desc')->find(); $keyrow=DB::query("SELECT * from wxd_wx_keyrepay where store_id='".$wechat['store_id']."' AND isshow=1 AND (keyword LIKE '%".$key."%' or isdefault=2) ORDER BY isdefault ASC,id desc LIMIT 1")[0]; } if ($keyrow) { switch ($keyrow['wxdtype']) { case 'cont': $type = 1; $content = $keyrow['value']; break; case 'link': $type = 1; $content = urldecode($keyrow['value']); break; case 'pic': $type = 2; $content = $keyrow['media_id']; break; case 'piccont': $type = 3; mlog("多图文值:" . $keyrow['value'], "reply/".$wxid); $piclist = M('wx_menulistdet')->where(array('store_id' => $wechat['store_id'], 'groupid' => $keyrow['value']))->order('ordno asc')->select(); if ($piclist) { $picount = 0; //logintitle,loginremark,loginimgurl,weburl ordno foreach ($piclist as $k => $v) { $picount = $picount + 1; $post_data["logintitle"] = $v['logintitle']; $post_data["loginremark"] = $v['loginremark']; $post_data["loginimgurl"] = QCLOUD_IMGURL . $v['loginimgurl']; $post_data["weburl"] = $v['weburl']; $newarry[] = $post_data; } } $content = array('piccount' => $picount, 'piclist' => $newarry); break; case 'dkf': $type = 4; $content = $keyrow['value']; break; default: break; } } else { $type = 0; $content = ''; } $data = array('type' => $type, 'content' => $content); mlog(json_encode($data), "reply/".$wxid); return json_encode($data); } //下载二维码 public function wximgdl() { // $filename = "http://open.weixin.qq.com/qr/code/?username=gh_75da794dc001"; // header("Content-Type: application/force-download"); // header('Content-Disposition: attachment; filename="'.$filename.'.jpg"'); // $img = file_get_contents($filename); // //echo $img; } //****************************api******************************************************// //公众号默认首页 public function wxsq() { // $url = 'http://jmh.xinda100.cn/index/weixin/login'; //正式 // $resp = httpRequest($url, "GET"); // $this->assign('getxqurl',$resp); $wxchat = M('wx_user')->where(' store_id=' . getAdmStoId())->find(); $this->assign('getstoid',getAdmStoId()); if ($wxchat['wxstate'] == '1') { $this->redirect($_SERVER['HTTP_HOST'] . '/Admin/Wechat/call?appid=' . $wxchat['appid'], 302); } else { //$ee = $_SERVER['HTTP_HOST']; // echo json_encode($wxchat); // exit(); // $this->assign('wxchat',json_encode($wxchat)); // upload_ylp_log('公众号配置'); return $this->fetch('', getAdmStoId()); } //查询是否已授权,如果已授权直接到定向到公众号详情页 } //公众号信息页 public function call($appid) { $resl = M('wx_user')->where('appid', $appid)->find(); //$_SESSION["appid"]=$appid; //处理订阅号和服务号 switch ($resl['type']) { case 2: $type = "服务号"; break; default: $type = "订阅号"; break; } //处理订阅号和服务号 switch ($resl['verify_type_info']) { case -1: $verify_type_info = "未认证"; break; // case 0: // $verify_type_info="微信认证"; // break; // case 1: // $verify_type_info="新浪微博认证"; // break; // case 2: // $verify_type_info="腾讯微博认证"; // break; default: $verify_type_info = "已认证"; break; } $sq_func_info = $resl[sq_func_info]; $func_info = explode(',', $sq_func_info); for ($i = 0; $i < (count($func_info) - 1); $i++) { //echo $hello[$index];echo "
"; switch ($func_info[$i]) { case 1: $func_info[$i] = "消息管理权限"; break; case 2: $func_info[$i] = "用户管理权限"; break; case 3: $func_info[$i] = "帐号服务权限"; break; case 4: $func_info[$i] = "网页服务权限"; break; case 5: $func_info[$i] = "微信小店权限"; break; case 6: $func_info[$i] = "微信多客服权限"; break; case 7: $func_info[$i] = "群发与通知权限"; break; case 8: $func_info[$i] = "微信卡券权限"; break; case 9: $func_info[$i] = "微信扫一扫权限"; break; case 10: $func_info[$i] = "微信连WIFI权限"; break; case 11: $func_info[$i] = "素材管理权限"; break; case 12: $func_info[$i] = "微信摇周边权限"; break; case 13: $func_info[$i] = "微信门店权限"; break; case 14: $func_info[$i] = "微信支付权限"; break; case 15: $func_info[$i] = "自定义菜单权限"; break; default: $func_info[$i] = ""; break; } } $this->assign('func_info', $func_info); $this->assign('verify_type_info', $verify_type_info); $this->assign('type', $type); $this->assign('res', $resl); $this->assign('appid', $appid); $storeid=getAdmStoId(); $this->assign('getstoid', $storeid); $wxlist = M('wx_ewmlist')->where(array('store_id' => $storeid,'scene_id'=>''))->find(); if ($wxlist) { $this->assign('ticket', $wxlist['ticket']); } else { $weixin_config = M('wx_user')->where('store_id=' . $storeid)->find(); //获取微信配置 if ($weixin_config ) { if (empty($weixin_config['appid']) || empty($weixin_config['appsecret'])) { $this->error('微信基本信息未配置', U('Wechat/setting')); exit; } $scene_id = ''; $return = M('wx_ewmlist')->where(array('store_id' => $storeid, 'scene_id' => $scene_id))->find(); if (empty($return)) { $access_token = m_get_access_token($weixin_config, $storeid); if ($access_token) { //获取数据的地址(微信提供) $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token; //发送给微信服务器的数据 $jsonstr = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ' . $scene_id . '}}}'; $return = httpRequest($url, 'POST', $jsonstr); mlog($return, 'bulidewm_return'); $return = json_decode($return, 1); if (!empty($return['ticket'])) { $v['ticket'] = $return['ticket']; $v['store_id'] = $storeid; $v['scene_id'] = $scene_id; $v['date'] = time(); $v['loadurl'] = $return['url']; M('wx_ewmlist')->add($v); $this->assign('ticket', $return['ticket']); } } } } } // upload_ylp_log('公众号'); return $this->fetch('call'); } //添加 public function updatecall() { // $jsonres["STATE"] = -1; // $jsonres["MSG"] = "Faile"; // return json_encode($jsonres); $data = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; mlog($data, "updatecall/".getAdmStoId()); // $data="{\"authorization_data\":{\"authorization_info\":{\"authorizer_appid\":\"wx2ea7cdd3ef52cdff\",\"authorizer_access_token\":\"14_c3YWQ9UAePNw-jmX9eZNsUt4lEaWbEpBxFJJgVhceF4df46y_r2s4kmGnraGt-ybtg327IkGdKb8hoiZDqyqqB3tg0vFB5QDCJwWVIjnIfEHmZHdztdXsO8fCRSt-IiePY52pCnJ3047i8M4GWQdADDCSM\",\"expires_in\":7200,\"authorizer_refresh_token\":\"refreshtoken@@@cFOBqVDUL4mnAAA5F68-HmTVFCLoltqY-LlhXrXVLwA\",\"func_info\":[{\"funcscope_category\":{\"id\":17}},{\"funcscope_category\":{\"id\":18},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":19}},{\"funcscope_category\":{\"id\":25},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":30},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":31},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":36}},{\"funcscope_category\":{\"id\":37}},{\"funcscope_category\":{\"id\":40}}]}},\"authorizer_info_data\":{\"authorizer_info\":{\"nick_name\":\"\u4e07\u4fe1\u8fbe\u5546\u57ce\",\"head_img\":\"http:\/\/wx.qlogo.cn\/mmopen\/FSGqibZR1LmOxO2pcLncdOn19nRHCCibOBxX3PibRP7P8zRIicSa3RbXRBtpDCZlLuqwia1sJ5xy2ohlpyQvQbiabN7VfibjRxQuW3ic\/0\",\"service_type_info\":{\"id\":0},\"verify_type_info\":{\"id\":0},\"user_name\":\"gh_06a05c5f072f\",\"alias\":\"\",\"qrcode_url\":\"http:\/\/mmbiz.qpic.cn\/mmbiz_jpg\/GTqBtp1Vn6SUDh2zC1bJW9T3ib4FkFLJQkRJFgYqVz1ia9NCy0RMLYbiaicUbKcj7avcdiaVibABOyHuKPXjwiaU6lGSA\/0\",\"business_info\":{\"open_pay\":1,\"open_shake\":0,\"open_scan\":0,\"open_card\":0,\"open_store\":0},\"idc\":1,\"principal_name\":\"\u6cc9\u5dde\u5e02\u4e07\u4fe1\u8fbe\u4fe1\u606f\u6280\u672f\u6709\u9650\u516c\u53f8\",\"signature\":\"\u5316\u5986\u54c1\u670d\u52a1\",\"MiniProgramInfo\":{\"network\":{\"RequestDomain\":[\"https:\/\/test-weshop.yolipai.net\"],\"WsRequestDomain\":[],\"UploadDomain\":[],\"DownloadDomain\":[],\"BizDomain\":[\"https:\/\/qa-mshop.yolipai.net\",\"https:\/\/mshop.yolipai.net\"]},\"categories\":[],\"visit_status\":0}},\"authorization_info\":{\"authorizer_appid\":\"wx2ea7cdd3ef52cdff\",\"authorizer_refresh_token\":\"refreshtoken@@@cFOBqVDUL4mnAAA5F68-HmTVFCLoltqY-LlhXrXVLwA\",\"func_info\":[{\"funcscope_category\":{\"id\":17}},{\"funcscope_category\":{\"id\":18},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":19}},{\"funcscope_category\":{\"id\":25},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":30},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":31},\"confirm_info\":{\"need_confirm\":0,\"already_confirm\":0,\"can_confirm\":0}},{\"funcscope_category\":{\"id\":36}},{\"funcscope_category\":{\"id\":37}},{\"funcscope_category\":{\"id\":40}}]}},\"stoid\":1,\"auth_type\":2}"; if ($data != null) { $res = json_decode($data);// $getauth_type=1; if ($res->auth_type) { $getauth_type = $res->auth_type; } if ($getauth_type==1) { $appid = $res->authorization_data->authorization_info->authorizer_appid; $datasql['appid'] = $res->authorization_data->authorization_info->authorizer_appid; //开启的权限集 $funcstr = ""; $func_info = $res->authorization_data->authorization_info->func_info; foreach ($func_info as $item) { $funcstr .= $item->funcscope_category->id . ","; } //file_put_contents(dirname(__FILE__)."/static/func_info.txt", $funcstr); $datasql['sq_func_info'] = $funcstr; $datasql['wxname'] = $res->authorizer_info_data->authorizer_info->nick_name; $datasql['headerpic'] = $res->authorizer_info_data->authorizer_info->head_img; $datasql['type'] = $res->authorizer_info_data->authorizer_info->service_type_info->id; $datasql['verify_type_info'] = $res->authorizer_info_data->authorizer_info->verify_type_info->id; $datasql['wxid'] = $res->authorizer_info_data->authorizer_info->user_name; $datasql['weixin'] = $res->authorizer_info_data->authorizer_info->alias; $datasql['qrcode_url'] = 'https://wechat.yolipai.com/weixin/wechat/download_wechat_url?wxOriginalId=' . $res->authorizer_info_data->authorizer_info->user_name; $datasql['principal_name'] = $res->authorizer_info_data->authorizer_info->principal_name; $datasql['signature'] = $res->authorizer_info_data->authorizer_info->signature; $datasql['wxstate'] = 1; $datasql['wait_access'] = 1; $datasql['store_id'] = $res->stoid; mlog("提交内容".json_encode($datasql), "updatecall/" . $res->stoid); $resu = M('wx_user')->where('store_id', $res->stoid)->find(); if (!$resu) { $datasql['authorizer_access_token'] = $res->authorization_data->authorization_info->authorizer_access_token; $datasql['authorizer_expires'] = time()+7100; $datasql['authorizer_refresh_token'] = $res->authorization_data->authorization_info->authorizer_refresh_token; $datasql['token'] = $appid . time(); $row = M('wx_user')->insertGetId($datasql); } else { if (empty($resu['token'])) { $datasql['token'] = $appid . time(); } if (empty($resu['authorizer_access_token']) || $resu['authorizer_refresh_token']!=$res->authorization_data->authorization_info->authorizer_refresh_token) { $datasql['authorizer_access_token'] = $res->authorization_data->authorization_info->authorizer_access_token; $datasql['authorizer_expires'] = time()+7100; $datasql['authorizer_refresh_token'] = $res->authorization_data->authorization_info->authorizer_refresh_token; } $row = M('wx_user')->where('store_id', $res->stoid)->save($datasql); } } else { mlog("执行小程序", "updatecall/".getAdmStoId()); //小程序 $appid = $res->authorization_data->authorization_info->authorizer_appid; $datasql['appid'] = $res->authorization_data->authorization_info->authorizer_appid; //开启的权限集 $funcstr = ""; $func_info = $res->authorization_data->authorization_info->func_info; foreach ($func_info as $item) { $funcstr .= $item->funcscope_category->id . ","; } $datasql['sq_func_info'] = $funcstr; $datasql['nick_name'] = $res->authorizer_info_data->authorizer_info->nick_name; $datasql['head_img'] = $res->authorizer_info_data->authorizer_info->head_img; $datasql['service_type_info'] = $res->authorizer_info_data->authorizer_info->service_type_info->id; $datasql['verify_type_info'] = $res->authorizer_info_data->authorizer_info->verify_type_info->id; $datasql['user_name'] = $res->authorizer_info_data->authorizer_info->user_name; $datasql['alias'] = $res->authorizer_info_data->authorizer_info->alias; $datasql['qrcode_url'] = $res->authorizer_info_data->authorizer_info->qrcode_url; $datasql['principal_name'] = $res->authorizer_info_data->authorizer_info->principal_name; $datasql['signature'] = $res->authorizer_info_data->authorizer_info->signature; $datasql['MiniProgramInfo'] = json_encode($res->authorizer_info_data->authorizer_info->MiniProgramInfo); $datasql['business_info'] = json_encode($res->authorizer_info_data->authorizer_info->business_info); $datasql['store_id'] = $res->stoid; $resu = M('weapp')->where('store_id', $res->stoid)->find(); $datasql['addtime']=time(); $getaction = "set"; $getauthorizer_access_token_new=""; if (!$resu) { $getauthorizer_access_token_new= $res->authorization_data->authorization_info->authorizer_access_token; $datasql['authorizer_access_token'] = $res->authorization_data->authorization_info->authorizer_access_token; $datasql['authorizer_expires'] = time()+7100; $datasql['authorizer_refresh_token'] = $res->authorization_data->authorization_info->authorizer_refresh_token; $getauthorizer_access_token_new= $res->authorization_data->authorization_info->authorizer_access_token; $row = M('weapp')->insertGetId($datasql); } else { if (empty($resu['authorizer_access_token']) || $resu['authorizer_refresh_token']!=$res->authorization_data->authorization_info->authorizer_refresh_token) { $datasql['authorizer_access_token'] = $res->authorization_data->authorization_info->authorizer_access_token; $datasql['authorizer_expires'] = time()+7100; $datasql['authorizer_refresh_token'] = $res->authorization_data->authorization_info->authorizer_refresh_token; } $getauthorizer_access_token_new=$resu['authorizer_access_token']; $row = M('weapp')->where('store_id', $res->stoid)->save($datasql); } if ($row) { //设置小程序域名 $getapiurl=str_replace("yolipai.net/","yolipai.net",WEAPPAPIURL); $requestdomain = $getapiurl . ",https://vv.video.qq.com"; $wsrequestdomain = ""; $uploaddomain = $getapiurl; $downloaddomain = $getapiurl . ",https://mshopimg.yolipai.net,https://wx.qlogo.cn"; $getstoid = $res->stoid; $getpostr = "POST"; $postdatastr = '{"action":"' . $getaction . '","requestdomain":[' . $this->getexp_str($requestdomain) . '],"wsrequestdomain":[' . $this->getexp_str($wsrequestdomain) . '],"uploaddomain":[' . $this->getexp_str($uploaddomain) . '],"downloaddomain":[' . $this->getexp_str($downloaddomain) . ']}'; $res = httpRequest("https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $getauthorizer_access_token_new, $getpostr, $postdatastr); mlog("执行域名".json_encode($res), "updatecall/".getAdmStoId()); } // } $jsonres["STATE"] = 1; $jsonres["MSG"] = "SUCCESS"; } else { $jsonres["STATE"] = -1; $jsonres["MSG"] = "Faile"; } return json_encode($jsonres); } //分割 public function getexp_str($requestdomain) { $requestdomain1 = explode(",", $requestdomain); $new_requestdomain = ""; if ($requestdomain1) { foreach ($requestdomain1 as $k => $v) { if ($new_requestdomain) { $new_requestdomain .= ',"' . $v . '"'; } else { $new_requestdomain = '"' . $v . '"'; } } } return $new_requestdomain; } public function index() { $wechat_list = M('wx_user')->where(' store_id=' . getAdmStoId())->select(); $this->assign('lists', $wechat_list); return $this->fetch('', getAdmStoId()); } public function add() { $exist = M('wx_user')->where(' store_id=' . getAdmStoId())->select(); if ($exist[0]['id'] > 0) { $this->error('只能添加一个公众号噢'); exit; } if (IS_POST) { $data = I('post.'); $data['create_time'] = time(); $data['token'] = get_rand_str(6, 1, 0); $row = DB::name('wx_user')->insertGetId($data); if ($row) { // upload_ylp_log('添加公众号'); $this->success('添加成功', U('Admin/Wechat/setting', array('id' => $row))); } else { $this->error('操作失败'); } exit; } return $this->fetch('', getAdmStoId()); } public function del() { $id = I('get.id'); $row = M('wx_user')->where(array('id' => $id))->delete(); if ($row) { // upload_ylp_log('删除公众号'); $this->success('操作成功'); } else { $this->error('操作失败'); } } public function setting() { $id = getAdmStoId(); //$erpid=tpCache('shop_info.ERPId',$id); $dir=ROOT_PATH.'/public/cert/'.$id.'/apiclient_cert.pem'; $isup=0; //创建目录失败 if(file_exists($dir)){ $this->assign('isup', 1); $isup=1; } $wechat = M('wx_user')->where(array('store_id' => $id))->find(); if (!$wechat) { $this->error("公众号不存在"); exit; } if (IS_POST) { $post_data = input('post.'); foreach ($post_data as $k => $v) { $post_data[$k] = trim($v); } if (empty($wechat['token'])) { $post_data['token'] = $wechat['appid'] . time(); } $row = M('wx_user')->where(array('store_id' => $id))->update($post_data); if ($row!==false){ //有上传证书要校验一遍 if($isup) { $getcheck_json=$this->check_zip(1); if ($getcheck_json['code']!= 1) { $this->error($getcheck_json['msg']); exit(); } } upload_ylp_log('B32支付配置编辑/确认提交'); $this->success("修改成功"); }else{ $this->error("修改失败"); } } $this->assign('wechat', $wechat); if($wechat['check_json']){ $c_json=json_decode($wechat['check_json'],true); $this->assign('c_json', $c_json); } return $this->fetch('', getAdmStoId()); } public function wxmenu() { $wechat = M('wx_user')->where("store_id=" . getAdmStoId())->find(); if (IS_POST) { $post_menu = input('post.menu/a'); //dump($post_menu);exit; //查询数据库是否存在 $menu_list = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'gzstate' => '0'))->getField('id', true); foreach ($post_menu as $k => $v) { $v['token'] = $wechat['token']; $v['store_id'] = getAdmStoId(); $v['gzstate'] = 0; if (in_array($k, $menu_list)) { //更新 // upload_ylp_log('更新菜单'); M('wx_menu')->where(array('id' => $k))->save($v); } else { //插入 // upload_ylp_log('增加菜单'); M('wx_menu')->where(array('id' => $k))->add($v); } } // echo json_encode(input('post.hidtype/a')) ; // echo "
"; // echo I("hidtype"); // echo $_POST["hidtype"].value; //echo json_encode($post_menu); //exit; if (I("hidtype") == 1) { $this->success('操作成功,进入发布步骤', U('Admin/Wechat/pub_menu')); exit; } } //获取最大ID //$max_id = M('wx_menu')->where(array('token'=>$wechat['token']))->field('max(id) as id')->find(); $max_id = DB::query("SHOW TABLE STATUS WHERE NAME = '__PREFIX__wx_menu'"); $max_id = $max_id[0]['auto_increment']; //获取父级菜单 $p_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => 0, 'gzstate' => 0))->order('id ASC')->select(); $p_menus = convert_arr_key($p_menus, 'id'); //获取二级菜单 $c_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => array('gt', 0), 'gzstate' => 0))->order('id ASC')->select(); $c_menus = convert_arr_key($c_menus, 'id'); $this->assign('p_lists', $p_menus); $this->assign('c_lists', $c_menus); $this->assign('max_id', $max_id ? $max_id - 1 : 0); $this->assign('erpid', getERPId()); return $this->fetch('', getAdmStoId()); } public function gzset() { $stoid = getAdmStoId(); $wechat = M('wx_user')->where("store_id=" . $stoid)->find(); if (IS_POST) { $post_data = input('post.'); if (!empty($post_data['id'])) { $row = M('wx_menu')->where(array('store_id' => $stoid, gzstate => 1))->update($post_data); } else { $post_data['level'] = "1"; $post_data['name'] = "关注自动回复"; $post_data['token'] = $wechat['token']; $post_data['pid'] = "0"; $post_data['store_id'] = $stoid; $post_data['gzstate'] = 1; $row = M('wx_menu')->save($post_data); } $row && exit($this->success("修改成功")); // upload_ylp_log('修改关注自动回复'); exit($this->error("修改失败")); } //获取父级菜单 $gzset = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => 0, 'gzstate' => 1))->find(); $this->assign('gzset', $gzset); return $this->fetch('', getAdmStoId()); } /* * 删除菜单 */ public function del_menu() { $id = I('get.id'); if (!$id) { exit('fail'); } $row = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'id' => $id))->delete(); $row && M('wx_menu')->where(array('store_id' => getAdmStoId(), 'pid' => $id))->delete(); //删除子类 if ($row) { // upload_ylp_log('删除菜单'); exit('success'); } else { exit('fail'); } } /* * 生成微信菜单 */ public function pub_menu() { $menu = array(); $menu['button'][] = array( 'name' => '测试', 'type' => 'view', 'url' => 'http://wwwtp-shhop.cn' ); $menu['button'][] = array( 'name' => '测试', 'sub_button' => array( array( "type" => "scancode_waitmsg", "name" => "系统拍照发图", "key" => "rselfmenu_1_0", "sub_button" => array() ) ) ); //获取菜单 $wechat = M('wx_user')->where(' store_id=' . getAdmStoId())->find(); //获取父级菜单 $p_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => 0, 'gzstate' => 0))->order('sort ASC')->select(); $p_menus = convert_arr_key($p_menus, 'id'); $post_str = $this->convert_menu($p_menus, $wechat['token']); mlog("发布菜单值:" . $post_str, "pub_menu/".getAdmStoId()); // http post请求 if (!count($p_menus) > 0) { $this->error('没有菜单可发布', U('Wechat/menu')); exit; } mlog("开始", "accesstoken/".getAdmStoId()); //$access_token = $this->get_access_token($wechat['appid'], $wechat['appsecret']); $access_token = m_get_access_token($wechat,getAdmStoId()); mlog("结束:" . $access_token, "accesstoken"); if (!$access_token) { $this->error('获取access_token失败', U('Wechat/menu')); // http://www.tpshop.com/index.php/Admin/Wechat/menu exit; } $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token}"; // exit($post_str); $return = httpRequest($url, 'POST', $post_str); $return = json_decode($return, 1); if ($return['errcode'] == 0) { $this->success('菜单已成功生成', U('Wechat/menu')); } else { //$this->error("错误代码;".$return['errcode']."微信服务繁忙,请稍后再试",U('Wechat/menu')); switch ($return['errcode']) { case "40054": $this->error("子菜单设置外链过长或错误", U('Wechat/menu')); break; case "40016": $this->error("顶级菜单设置外链过长或错误", U('Wechat/menu')); break; case "40001": $web_expires = time() - 7200; M('wx_user')->where(array('store_id' => getAdmStoId(), 'id' => $wechat['id']))->save(array('web_expires' => $web_expires)); $this->error("错误代码;" . $return['errcode'] . "微信服务繁忙,请重新发布", U('Wechat/menu')); break; default: $this->error("错误代码;" . $return['errcode'].$return['errmsg'] . "微信服务繁忙,请稍后再试", U('Wechat/menu')); break; } // echo "错误代码;".$return['errcode']; // echo "微信服务繁忙,请稍后再试"; exit; } } //菜单转换 //菜单转换 private function convert_menu($p_menus, $token) { $weappres=M('weapp')->where(array('store_id'=>getAdmStoId()))->find(); $key_map = array( 'scancode_waitmsg' => 'rselfmenu_0_0', 'scancode_push' => 'rselfmenu_0_1', 'pic_sysphoto' => 'rselfmenu_1_0', 'pic_photo_or_album' => 'rselfmenu_1_1', 'pic_weixin' => 'rselfmenu_1_2', 'location_select' => 'rselfmenu_2_0', ); $new_arr = array(); $count = 0; foreach ($p_menus as $k => $v) { $new_arr[$count]['name'] = $v['name']; //获取子菜单 $c_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $token, 'pid' => $k, 'gzstate' => 0))->order('sort ASC')->select(); if ($c_menus) { foreach ($c_menus as $kk => $vv) { $add = array(); $add['name'] = $vv['name']; $add['type'] = $vv['type']; // click类型 switch ($add['type']) { case "click": $add['key'] = $vv['id']; break; case "view": $add['url'] = $vv['value']; break; case "miniprogram": $add['url'] = $vv['value']; $add['appid'] = $vv['we_appid']; $add['pagepath'] = $vv['we_pagepath']; break; default: $add['key'] = $vv['id']; break; } $add['sub_button'] = array(); if ($add['name']) { $new_arr[$count]['sub_button'][] = $add; } } } else { $new_arr[$count]['type'] = $v['type']; // click类型 switch ($new_arr[$count]['type']) { case "click": $new_arr[$count]['key'] = $v['id']; break; case "view": $new_arr[$count]['url'] = $v['value']; break; case "miniprogram": $new_arr[$count]['url'] = $v['value']; $new_arr[$count]['appid'] = $v['we_appid']; $new_arr[$count]['pagepath'] = $v['we_pagepath']; break; default: $new_arr[$count]['key'] = $v['id']; break; } } $count++; } // return json_encode(array('button'=>$new_arr)); return json_encode(array('button' => $new_arr), JSON_UNESCAPED_UNICODE); } /* * 文本回复 */ public function text() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'TEXT'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.keyword,t.text FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_text AS t ON t.id = k.pid and t.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND k.store_id=" . getAdmStoId() . " AND type = 'TEXT' ORDER BY t.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('count', $count); $this->assign('page', $show); $this->assign('lists', $lists); $this->assign('wechat', json_encode($wechat)); return $this->fetch('', getAdmStoId()); } /* * 添加文本回复 */ public function add_text() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); if (IS_POST) { $edit = I('get.edit'); $add['keyword'] = I('post.keyword'); $add['token'] = $wechat['token']; $add['text'] = I('post.text'); $add['store_id'] = getAdmStoId(); if (!$edit) { //添加模式 $add['createtime'] = time(); $add['pid'] = DB::name('wx_text')->insertGetId($add); unset($add['text']); unset($add['createtime']); $add['type'] = 'TEXT'; $row = M('wx_keyword')->add($add); } else { //编辑模式 $id = I('post.kid'); $model = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id)); $data = $model->find(); if ($data) { $update = I('post.'); $update['type'] = 'TEXT'; M('wx_keyword')->where(array('id' => $id))->save($update); $row = M('wx_text')->where(array('id' => $data['pid']))->save($add); } } // upload_ylp_log('增加关键字回复-文字'); $row ? $this->success("添加成功", U('Admin/Wechat/text')) : $this->error("添加失败", U('Admin/Wechat/text')); exit; } $id = I('get.id'); if ($id) { $sql = "SELECT k.id,k.keyword,t.text FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_text AS t ON t.id = k.pid and t.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND k.id = {$id} AND k.store_id=" . getAdmStoId() . " AND k.type = 'TEXT'"; $data = DB::query($sql); $this->assign('keyword', $data[0]); } return $this->fetch('', getAdmStoId()); } /* * 删除文本回复 */ public function del_text() { $id = I('get.id'); $row = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->find(); if ($row) { M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->delete(); M('wx_text')->where(array('store_id' => getAdmStoId(), 'id' => $row['pid']))->delete(); // upload_ylp_log('删除关键字回复-文字'); $this->success("删除成功"); } else { $this->error("删除失败"); } } /* * 图文列表 */ public function img() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'IMG'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.keyword,i.title,i.url,i.pic,i.desc FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_img i ON i.id = k.pid and i.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND k.store_id=" . getAdmStoId() . " and type = 'IMG' ORDER BY i.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('page', $show); $this->assign('lists', $lists); $this->assign('wechat', $wechat); return $this->fetch('', getAdmStoId()); } /* * 添加图文回复 */ public function add_img() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); if (IS_POST) { $add['keyword'] = I('post.keyword'); $add['token'] = $wechat['token']; $add['title'] = I('post.title'); $add['desc'] = I('post.desc'); $add['pic'] = I('post.pic'); //封面图片 //if(!strstr($add['pic'],'https')) ////$add['pic'] = SITE_URL.$add['pic']; $add['url'] = I('post.url'); // 商品地址 或 其他 $add['goods_id'] = I('post.goods_id'); $add['goods_name'] = I('post.goods_name'); //商品名字 $add['webcontent'] = I('post.goods_content'); //文章正文 empty($add['keyword']) && $this->error("关键词不得为空"); empty($add['title']) && $this->error("标题不得为空"); empty($add['url']) && $this->error("url不得为空"); empty($add['pic']) && $this->error("封面图片不得为空"); empty($add['desc']) && $this->error("简介不得为空"); $edit = I('get.edit'); if (!$edit) { //添加模式 $add['createtime'] = time(); $add['store_id'] = getAdmStoId(); //$add['pic'] = SITE_URL.$add['pic']; $wx_img_last_ins_id = DB::name('wx_img')->insertGetId($add); $add['pid'] = $wx_img_last_ins_id; $add['type'] = 'IMG'; $row = M('wx_keyword')->add($add); // upload_ylp_log('增加关键字回复-图文'); $row ? $this->success("添加成功", U('Admin/Wechat/img')) : $this->error("添加失败", U('Admin/Wechat/img')); exit; } else { //编辑模式 $id = I('post.kid'); $model = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id, 'type' => 'IMG')); $data = $model->find(); if ($data) { $update = input('post.'); $update['type'] = 'IMG'; M('wx_keyword')->where(array('id' => $id))->save($update); $add['uptatetime'] = time(); $row = M('wx_img')->where(array('id' => $data['pid']))->save($add); } // upload_ylp_log('修改关键字回复-图文'); $row ? $this->success("修改成功", U('Admin/Wechat/img')) : $this->error("修改失败", U('Admin/Wechat/img')); exit; } } $id = I('get.id'); if ($id) { $sql = "SELECT k.id,k.keyword,i.title,i.url,i.pic,i.desc,i.webcontent FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_img i ON i.id = k.pid and i.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND type = 'IMG' AND k.id = {$id} and k.store_id=" . getAdmStoId(); $data = DB::query($sql); $this->assign('keyword', $data[0]); } $this->assign('erpid', getERPId()); return $this->fetch('', getAdmStoId()); } /* * 选择商品 * //todo * //与wap端一起做 */ public function select_goods() { $url = 'http://' . $_SERVER['HTTP_HOST']; //http://www.tp-shop.cn/index.php?m=Home&c=Goods&a=info&id= $count = M('goods')->where(' store_id=' . getAdmStoId())->count(); $pager = new Page($count, 10); //$sql = "SELECT k.id,k.keyword,t.text FROM tp_wx_keyword k LEFT JOIN tp_wx_text AS t ON t.id = k.pid WHERE k.token = '{$wechat['token']}' AND type = 'TEXT' ORDER BY t.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $sql = "SELECT goods_name,shop_price, CONCAT('{$url}/index.php?m=Home&c=Goods&a=info&id=',goods_id) AS goods_url, CONCAT('{$url}/',original_img) AS original_img FROM __PREFIX__goods where store_id=" . getAdmStoId() . " ORDER BY goods_id DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $lists = DB::query($sql); $this->assign('page', $show); $this->assign('lists', $lists); return $this->fetch('', getAdmStoId()); } /* * 删除图文回复 */ public function del_img() { $id = I('get.id'); $row = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->find(); if ($row) { $img = M('wx_img')->where('id=' . $row['pid'])->where('store_id', getAdmStoId())->find(); if ($img) { $dellogo = ltrim($img['pic'], '/'); if (!empty($dellogo)) { vendor('qcloudcos.myqcloudcos'); $rs = Myqcloudcos::delFile('wxd', $dellogo); mdelFile(ROOT_PATH . $dellogo); } } M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->delete(); M('wx_img')->where(array('store_id' => getAdmStoId(), 'id' => $row['pid']))->delete(); // upload_ylp_log('删除图文回复'); $this->success("删除成功"); } else { $this->error("删除失败"); } } /* * 多图文消息列表 */ public function news() { $wechat = M('wx_user')->where(' and store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'NEWS'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.keyword,k.pid,i.img_id FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_news i ON i.id = k.pid and k.store_id=i.store_id WHERE k.token = '{$wechat['token']}' and store_id=" . getAdmStoId() . " AND type = 'NEWS' ORDER BY i.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('page', $show); $this->assign('lists', $lists); $this->assign('wechat', $wechat); return $this->fetch('', getAdmStoId()); } /* * 添加多图文 */ public function add_news() { $wechat = M('wx_user')->find(); if (IS_POST) { $arr = explode(',', I('post.img_id/s')); if ($arr) array_pop($arr); if (count($arr) <= 1) { $this->error("单图文请到图文回复设置", U('Admin/Wechat/news')); exit; } $add['keyword'] = I('post.keyword'); $add['token'] = $wechat['token']; $add['img_id'] = implode(',', $arr); $add['store_id'] = getAdmStoId(); //添加模式 $add['createtime'] = time(); $wx_news_last_ins_id = DB::name('wx_news')->insertGetId($add); $add['pid'] = $wx_news_last_ins_id; $add['type'] = 'NEWS'; $row = M('wx_keyword')->add($add); // upload_ylp_log('添加多图文'); $row ? $this->success("添加成功", U('Admin/Wechat/news')) : $this->error("添加失败", U('Admin/Wechat/news')); exit; } return $this->fetch('', getAdmStoId()); } /* * 删除多图文 */ public function del_news() { $id = I('get.id'); $row = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->find(); if ($row) { M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'id' => $id))->delete(); M('wx_news')->where(array('store_id' => getAdmStoId(), 'id' => $row['pid']))->delete(); // upload_ylp_log('删除多图文'); $this->success("删除成功"); } else { $this->error("删除失败"); } } /* * 预览多图文 */ public function preview() { $id = I('get.id'); $news = M('wx_news')->where(array('store_id' => getAdmStoId(), 'id' => $id))->find(); $lists = M('wx_img')->where(array('store_id' => getAdmStoId(), 'id' => array('in', $news['img_id'])))->select(); // exit(DB::getLastSql()); $first = $lists[0]; unset($lists[0]); $this->assign('first', $first); $this->assign('lists', $lists); // upload_ylp_log('预览多图文'); return $this->fetch('', getAdmStoId()); } public function select() { $wechat = M('wx_user')->where(' store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'IMG'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.pid,k.keyword,i.title,i.url,i.pic,i.desc FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_img i ON i.id = k.pid and i.store_id=k.store_id WHERE k.token = '{$wechat['token']}' and k.store_id=" . getAdmStoId() . " AND type = 'IMG' ORDER BY i.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('page', $show); $this->assign('lists', $lists); return $this->fetch('', getAdmStoId()); } public function get_access_token($appid, $appsecret) { //判断是否过了缓存期 $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); return m_get_access_token($wechat,getAdmStoId()); } public function nes() { return $this->fetch('', getAdmStoId()); } //微信菜单 public function menu() { // upload_ylp_log('微信菜单设置'); $wechat = M('wx_user')->where("store_id=" . getAdmStoId())->find(); $shopname = M('store')->where("store_id=" . getAdmStoId())->field('store_name')->select(); $shopname = $shopname[0]['store_name']; //查询 小程序 APPID $weapp_res=M('weapp')->where(array('store_id'=>getAdmStoId()))->find(); if ($weapp_res) { $this->assign('weapp_res', $weapp_res); } $ispost = I('ispost'); if ($ispost == 1) { $post_menu = input('post.menu/a'); //查询数据库是否存在 $menu_list = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token']))->getField('id', true);//,'gzstate'=>'0' $sort = 0; //dump($post_menu);exit; foreach ($post_menu as $k => $v) { $v['token'] = $wechat['token']; $v['store_id'] = getAdmStoId(); if (empty($v["gzstate"])) { $v['gzstate'] = 0; } else { $v['gzstate'] = 1; } if ($v["wxdtype"] == "pic") { $getvalue = explode('|', $v["value"]); $v["value"] = $getvalue[0]; $v["media_id"] = $getvalue[1]; } $v['sort'] = $sort; if (in_array($k, $menu_list)) { //更新 $r=M('wx_menu')->where(array('id' => $k))->save($v); if ($r){ if ($v['wxdtype']=='cont' || $v['wxdtype']=='pic' || $v['wxdtype']=='link'){ upload_ylp_log('B33发送消息编辑/保存'); } if ($v['wxdtype']=='piccont'){ upload_ylp_log('B34图文编辑/保存'); } if ($v['wxdtype']=='messagelink'){ upload_ylp_log('B35资讯编辑/保存'); } if ($v['wxdtype']=='prolink'){ upload_ylp_log('B36商品编辑/保存'); } if ($v['wxdtype']=='otherlink'){ upload_ylp_log('B37链接编辑/保存'); } } } else { //插入 M('wx_menu')->where(array('id' => $k))->add($v); $insid = M('wx_menu')->getLastInsID(); } $sort += 1; } // echo json_encode(input('post.hidtype/a')) ; // echo "
"; // echo I("hidtype"); // echo $_POST["hidtype"].value; //echo json_encode($post_menu); //exit; return json(['status' => 1, 'newid' => $insid]); } //获取最大ID //$max_id = M('wx_menu')->where(array('token'=>$wechat['token']))->field('max(id) as id')->find(); // $max_id = DB::query("SHOW TABLE STATUS WHERE NAME = '__PREFIX__wx_menu'"); // $max_id = $max_id[0]['auto_increment']; // // //获取父级菜单 // $p_menus = M('wx_menu')->where(array('store_id'=>getAdmStoId(),'token'=>$wechat['token'],'pid'=>0,'gzstate'=>0))->order('sort ASC')->select(); // $p_menus = convert_arr_key($p_menus,'id'); // //获取二级菜单 // $c_menus = M('wx_menu')->where(array('store_id'=>getAdmStoId(),'token'=>$wechat['token'],'pid'=>array('gt',0),'gzstate'=>0))->order('sort ASC')->select(); // $c_menus = convert_arr_key($c_menus,'id'); // //dump($p_menus);exit; // $this->assign('p_lists',$p_menus); // $this->assign('c_lists',$c_menus); // $this->assign('max_id',$max_id ? $max_id-1 : 0); $this->assign('erpid', getERPId()); $this->assign('shopname', $shopname); return $this->fetch('', getAdmStoId()); } //选择图文 public function text_img() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'IMG'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.keyword,i.title,i.url,i.pic,i.desc FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_img i ON i.id = k.pid and i.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND k.store_id=" . getAdmStoId() . " and type = 'IMG' ORDER BY i.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('page', $show); $this->assign('lists', $lists); $this->assign('wechat', $wechat); return $this->fetch('', getAdmStoId()); } //选择文本 public function text_txt() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); $count = M('wx_keyword')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'type' => 'TEXT'))->count(); $pager = new Page($count, 10); $sql = "SELECT k.id,k.keyword,t.text FROM __PREFIX__wx_keyword k LEFT JOIN __PREFIX__wx_text AS t ON t.id = k.pid and t.store_id=k.store_id WHERE k.token = '{$wechat['token']}' AND k.store_id=" . getAdmStoId() . " AND type = 'TEXT' ORDER BY t.createtime DESC LIMIT {$pager->firstRow},{$pager->listRows}"; $show = $pager->show(); $lists = DB::query($sql); $this->assign('count', $count); $this->assign('page', $show); $this->assign('lists', $lists); $this->assign('wechat', json_encode($wechat)); return $this->fetch('', getAdmStoId()); } //选择资讯20170508 public function search_article() { $Article = M('Article'); $list = array(); $p = input('p/d', 1); $size = input('size/d', 10); $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $keywords = trim(urldecode(urldecode(I('keywords')))); $keywords && $where['title'] = array('like', '%' . $keywords . '%'); $cat_id = I('cat_id/d', 0); $cat_id && $where['cat_id'] = $cat_id; $res = $Article->where($where)->order('add_time desc')->page("$p,$size")->select(); $count = $Article->where($where)->count();// 查询满足要求的总记录数 $pager = new Page($count, $size);// 实例化分页类 传入总记录数和每页显示的记录数 $page = $pager->show();//分页显示输出 $ArticleCat = new ArticleCatLogic(); $cats = $ArticleCat->article_cat_list(0, 0, false); if ($res) { foreach ($res as $val) { $val['category'] = $cats[$val['cat_id']]['cat_name']; $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); $list[] = $val; } } $this->assign('keywords',$keywords); $this->assign('cats', $cats); $this->assign('cat_id', $cat_id); $this->assign('list', $list);// 赋值数据集 $this->assign('page', $page);// 赋值分页输出 $this->assign('pager', $pager); // upload_ylp_log('文章列表'); return $this->fetch('', getAdmStoId()); } //选择商品20170508 public function search_goods() { $GoodsLogic = new GoodsLogic(); $brandList = $GoodsLogic->getSortBrands(); $categoryList = $GoodsLogic->getSortCategory(); $this->assign('categoryList', $categoryList); $this->assign('brandList', $brandList); $where = ' 1 = 1 '; // 搜索条件 I('intro') && $where = "$where and " . I('intro') . " = 1"; I('brand_id') && $where = "$where and brand_id = " . I('brand_id'); $brand_id=I('brand_id'); (I('is_on_sale') !== '') && $where = "$where and is_on_sale = " . I('is_on_sale'); $cat_id = I('cat_id'); // 关键词搜索 $key_word = I('key_word') ? trim(I('key_word')) : ''; if ($key_word) { $where = "$where and (goods_name like '%$key_word%' or goods_sn like '%$key_word%' or keywords like '%$key_word%')"; } $where .= " and store_id=" . getAdmStoId(); if ($cat_id > 0) { $grandson_ids = getCatGrandson($cat_id); $where .= " and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件 } $model = M('Goods'); $count = $model->where($where)->count(); $pager = new Page($count, 10); $show = $pager->show(); $goodsList = $model->where($where)->limit($pager->firstRow . ',' . $pager->listRows)->select(); $catList = D('goods_category')->where(" store_id=" . getAdmStoId())->select(); $catList = convert_arr_key($catList, 'id'); $this->assign('catList', $catList); $this->assign('goodsList', $goodsList); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('cat_id',$cat_id); $this->assign('brand_id',$brand_id); return $this->fetch('', getAdmStoId()); } //选择商品分组 public function search_goods_group() { $goods_group = M('goods_group'); $list = array(); $p = input('p/d', 1); $size = input('size/d', 5); $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $keywords = trim(I('keywords')); $keywords && $where['gpname'] = array('like', '%' . $keywords . '%'); $where['status'] = 1; $list = $goods_group->where($where)->order('gp_ordid asc,add_time asc')->page("$p,$size")->select(); $count = $goods_group->where($where)->count();// 查询满足要求的总记录数 $pager = new Page($count, $size);// 实例化分页类 传入总记录数和每页显示的记录数 $page = $pager->show();//分页显示输出 $this->assign('grouplist', $list);// 赋值数据集 $this->assign('page', $page);// 赋值分页输出 $this->assign('pager', $pager); return $this->fetch('', getAdmStoId()); } //获取微信菜单 public function ajax() { $wechat = M('wx_user')->where("store_id=" . getAdmStoId())->find(); //获取父级菜单 $p_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => 0, 'gzstate' => 0))->order('sort ASC')->select(); //获取二级菜单 $c_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'pid' => array('gt', 0), 'gzstate' => 0))->order('sort ASC')->select(); //获取关注触发 $g_menus = M('wx_menu')->where(array('store_id' => getAdmStoId(), 'token' => $wechat['token'], 'gzstate' => 1))->order('sort ASC')->limit(1)->select(); if (empty($p_menus)) { $jsonlist['state'] = "0"; $jsonlist['msg'] = '暂无'; } else { $jsonlist['state'] = "1"; $jsonlist['msg'] = '成功'; $jsonlist['item'] = $p_menus; if (empty($c_menus)) { $jsonlist['item1'] = ""; } else { $jsonlist['item1'] = $c_menus; } if (empty($g_menus)) { $jsonlist['item2'] = ""; } else { $jsonlist['item2'] = $g_menus; } } return json($jsonlist); } //微信触发消息 public function wxsendlist() { $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $key_word = I('key_word') ? trim(I('key_word')) : ''; if ($key_word) { $where['b.typename|a.typeid'] = array('like', '%' . $key_word . '%'); } $where['store_id'] = getAdmStoId(); $model = M('wx_sendlist'); $count = $model->alias('a')->join('wx_sendtype b', ' a.typeid=b.typeid')->where($where)->count(); $Page = new Page($count, $pagenum); $list = $model->alias('a')->join('wx_sendtype b', ' a.typeid=b.typeid')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('a.typeid asc')->select(); $show = $Page->show();//分页显示输出 $this->assign('page', $show);//赋值分页输出 $this->assign('list', $list); $this->assign('pager', $Page);//赋值分页输出 $this->assign('pagenum', $pagenum); $this->assign('oldurl', urlencode(curPageURL())); // $oldurl = urldecode(urldecode($oldurl)); // upload_ylp_log('微信消息设置'); return $this->fetch('', getAdmStoId()); } //消息模板测试 public function sendtest() { $getstoid = getAdmStoId(); $gid = I('post.sendid'); if (!empty($gid)) { $wxsend = M('wx_sendlist')->where(array('store_id' => $getstoid, 'sendid' => $gid))->find(); } $this->assign('wxsend', $wxsend); return $this->fetch('', getAdmStoId()); } public function sumbitsendtest() { $getstoid = getAdmStoId(); $gid = I('post.sendid'); $mobile = I('post.mobile'); $userinfo = M('users')->alias('a') ->join('wx_user b', 'a.store_id=b.store_id') ->field("a.*,b.appid,b.appsecret") ->where(array('a.store_id' => $getstoid, 'a.mobile' => $mobile))->find(); if ($userinfo) { if ($userinfo['openid'] != "") { $wxsend = M('wx_sendlist')->alias('a') ->where(array('a.store_id' => $getstoid, 'a.sendid' => $gid))->find(); if ($wxsend['template_type']=="1") { $wxsendtype=M('wx_sendtype')->where('typeid',$wxsend['typeid'])->find(); } else { $wxsendtype=M('wx_sendtypelist')->where(array('typeid'=>$wxsend['typeid'],'ordid'=>$wxsend['template_type']))->find(); } if ($wxsend) { $colorlist = urlencode("#FF0000|#173177|#173177|#173177|#173177|#173177|#FF0000|#ca003a"); $pd['colorlist'] = $colorlist; $pd['title'] = "测试标题"; $pd['key1'] = "关键字1"; $pd['key2'] = "关键字2"; $pd['key3'] = "关键字3";; $pd['key4'] = "关键字4"; $pd['key5'] = "关键字5"; $pd['remark'] = "备注"; $mdataarr = explode(",", $wxsendtype["myfieldlist"]); $postdata = null; /*--双数组,确定推送内容--*/ foreach ($mdataarr as $ku => $vu) { $postdata[] = $pd[$vu]; } $postdata[] = $colorlist; $backurl = ""; $jssdk = new \app\mobile\logic\Jssdk($userinfo['appid'], $userinfo['appsecret']); $r = $jssdk->WeiXin_MassageModelSend($userinfo['store_id'], $userinfo['openid'], $wxsend['typeid'], $backurl, $postdata,$wxsend); if ($r['wxcode'] == 0) { $return_arr = array('code' => 0, 'msg' => '发送成功', 'data' => '',); } else { $return_arr = array('code' => -1, 'msg' => '发送失败' . $r['msg'], 'data' => '',); } } } else { $return_arr = array('code' => -1, 'msg' => '该手机号未绑定线上会员', 'data' => '',); } } else { $return_arr = array('code' => -1, 'msg' => '会员手机号不存在', 'data' => '',); } $this->ajaxReturn($return_arr); } //添加推送消息 public function addwxsend() { $typwhere="1=1"; $erpid=getERPId(); if (empty($erpid)) { $typwhere=" typeid not in(1011,1012)"; } $oldurl = I('oldurl/s'); if ($oldurl) { $oldurl = urldecode(urldecode($oldurl)); } $getstoid = getAdmStoId(); $id = I('sendid'); //修改 if ($id) { $wxsend = M('wx_sendlist')->alias('a') ->join('wx_sendtype b', 'a.typeid=b.typeid', 'left') ->where(array('a.store_id' => $getstoid, 'a.sendid' => $id)) ->field('a.*,b.remark as type_remark,b.typestate') ->find(); if ($wxsend) { if (empty($wxsend['typestate'])) { $this->error('该模板微信官网已失效无法修改', U('Wechat/wxsendlist')); exit; } if ($wxsend['store_remark']) { $store_remark = json_decode($wxsend['store_remark'], true); $wxsend['first'] = $store_remark['first']; $wxsend['remark'] = $store_remark['remark']; } } // // } else { $wxsend['state']=1; $typwhere.=" and typeid not in(select typeid from wxd_wx_sendlist where store_id=".$getstoid.") and typestate=1 "; } $typelist = M('wx_sendtype')->where($typwhere)->order('typeid asc')->select(); if (IS_POST) { $data = input('post.'); $typeid = I('post.typeid'); $data['store_id'] = $getstoid; unset($data['wx_first']); unset($data['wx_remark']); $data['template_id']=trim(I('template_id')); $data['htmlurl']=trim(I('htmlurl')); if (I('post.wx_first') && I('post.wx_remark')) { $store_remark['first'] = I('post.wx_first'); $store_remark['remark'] = I('post.wx_remark'); $data['store_remark'] = json_encode($store_remark); } else { $data['store_remark']=""; } if ($id) { $data['sendid'] = $id; // upload_ylp_log('编辑推送消息'); M("wx_sendlist")->update($data); } else { $data['add_time'] = time(); $sendlist = M('wx_sendlist')->where(array('store_id' => $getstoid, 'typeid' => $typeid))->find(); if ($sendlist) { $this->error('该模板已存在!', U('Admin/Wechat/addwxsend')); exit(); } else { // upload_ylp_log('添加推送消息'); M("wx_sendlist")->insert($data); } } if ($oldurl) { upload_ylp_log('B44推送消息设置/确认提交'); $this->success("操作成功!!!", $oldurl); } else { $this->success("操作成功!!!", U('Admin/Wechat/wxsendlist')); } exit; } $this->assign('wxsend', $wxsend); $this->assign('typelist', $typelist); return $this->fetch('', getAdmStoId()); } //获取模板类型的格式 public function getwxremark(){ $model = M("wx_sendtype"); $res= $model->where(array('typeid' => $_GET['typeid']))->find(); if ($model) { $return_arr = array('status' => 1, 'msg' => '操作成功', 'remark' =>$res['remark']); } else{ $return_arr = array('status' => -1, 'msg' => '获取失败', 'data' => ''); } $this->ajaxReturn($return_arr); } public function getwxremark1(){ $model = M("wx_sendtypelist"); $res= $model->where(array('ordid' => $_GET['id']))->find(); if ($model) { $return_arr = array('status' => 1, 'msg' => '操作成功', 'remark' =>$res['remark']); } else{ $return_arr = array('status' => -1, 'msg' => '获取失败', 'data' => ''); } $this->ajaxReturn($return_arr); } /** * 获取 多个模板格式 */ public function template_typelist(){ $model = M("wx_sendtypelist"); $res= $model->where(array('typeid' => $_GET['typeid'])) ->field('typename,ordid') ->order('ordid asc,id asc') ->select(); if ($res) { $return_arr = array('status' => 1, 'msg' => '操作成功', 'list' =>$res); } else{ $return_arr = array('status' => -1, 'msg' => '获取失败', 'data' => ''); } $this->ajaxReturn($return_arr); } //删除推送消息 public function delsendlist() { $model = M("wx_sendlist"); $model->where(array('sendid' => $_GET['id'], 'store_id' => getAdmStoId()))->delete(); // upload_ylp_log('删除推送消息'); $return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',); $this->ajaxReturn($return_arr); } //选择素材 public function search_material() { $grouplist = Db::query("SELECT groupid,count(1)as num from wxd_wx_menulistdet where store_id='" . getAdmStoId() . "' GROUP BY groupid"); //var_dump(count($grouplist)); $list = M('wx_menulistdet')->where("store_id=" . getAdmStoId())->order("groupid,OrdNo")->select(); foreach ($grouplist as $item) { unset($temp); for ($i = 0; $i < count($list); $i++) { if ($item['groupid'] == $list[$i]['groupid']) { $temp[] = $list[$i]; } $item['data'] = $temp; } $item1[] = $item; } //var_dump($item1[0]['data'][1]); for ($k = 0; $k < count($item1); $k++) { $ky = $k % 3; switch ($ky) { case 0: $list1[] = $item1[$k]; break; case 1: $list2[] = $item1[$k]; break; default: $list3[] = $item1[$k]; break; } } // var_dump($list1); // var_dump($list1); // var_dump($list2); // var_dump($list3); $this->assign('list', $item1); $this->assign('list1', $list1); $this->assign('list2', $list2); $this->assign('list3', $list3); //var_dump($list1[0]["groupid"]); return $this->fetch('', getAdmStoId()); } //新建素材 public function create_material() { $wechat = M('wx_user')->where('store_id=' . getAdmStoId())->find(); $groupid = I('post.gid'); //'86f03ffe-c5ea-bdca-0269-eaec30ebd5a6'; if (empty($groupid)) { $groupid = uuid(); $this->assign('list', ''); } else { $list = M('wx_menulistdet')->where("store_id=" . getAdmStoId() . " and groupid='" . $groupid . "'")->order('ordno')->select(); mlog(json_encode($list), "11tt"); $this->assign('list', $list); } //var_dump(IS_POST); if (IS_POST) { $aid = I('aid'); $groupid1 = I('post.groupid'); $ordno = I('post.ordno/d') + 1; $add['groupid'] = $groupid1; $add['logintitle'] = I('post.logintitle'); $add['loginremark'] = I('post.loginremark'); $add['loginimgurl'] = I('post.loginimgurl'); //封面图片 $add['author'] = I('post.author'); $add['content'] = I('post.content'); //文章正文 $add['store_id'] = getAdmStoId(); $add['billdate'] = time(); if (empty($aid)) { mlog("新增" . $aid, "11tt"); $add['ordno'] = $ordno; $wx_img_last_ins_id = DB::name('wx_menulistdet')->insertGetId($add); //插入链接地址 unset($add); $add['id'] = $wx_img_last_ins_id; if (I('post.weburl')) { $add['weburl'] = I('post.weburl'); } else { $add['weburl'] = curHostURL() . "/Mobile/Article/articletw/stoid/" . getAdmStoId() . "/article_id/" . $wx_img_last_ins_id; } DB::name('wx_menulistdet')->update($add); } else { if (I('post.weburl')) { $add['weburl'] = I('post.weburl'); } else { $add['weburl'] = curHostURL() . "/Mobile/Article/articletw/stoid/" . getAdmStoId() . "/article_id/" . $aid; } $add['id'] = $aid; $wx_img_last_ins_id = D('wx_menulistdet')->update($add);//M('article')->where(array('article_id'=>$aid))->save($add); } if (empty($wx_img_last_ins_id)) { $jsonres["state"] = -1; $jsonres["msg"] = "FAIL"; $jsonres['twid'] = ''; } else { $jsonres["state"] = 1; $jsonres["msg"] = "SUCCESS"; $jsonres['twid'] = empty($aid) ? $wx_img_last_ins_id : $aid; } return json($jsonres); } $this->assign('erpid', getERPId()); $this->assign('groupid', $groupid); $this->initEditor(); // 编辑器 return $this->fetch('', getAdmStoId()); } //获取当前素材 public function singlearticle() { $id = I('post.id'); $list = M('wx_menulistdet')->where("store_id=" . getAdmStoId() . " and id=" . $id)->select(); mlog(json_encode($list), "11tt"); $this->assign('list', $list[0]); //var_dump($list); $this->assign('erpid', getERPId()); //var_dump(initEditor()); $this->initEditor(); // 编辑器 return $this->fetch('', getAdmStoId()); } //获取当前图文 public function getcurtw() { $groupid = I('post.gid'); $isdel = I('post.del'); if ($isdel) //删除 { $model = M("wx_menulistdet"); $model->where(array('groupid' => $groupid, 'store_id' => getAdmStoId()))->delete(); // upload_ylp_log('删除图文'); $return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',); $this->ajaxReturn($return_arr); } else { $list = M('wx_menulistdet')->where("store_id=" . getAdmStoId() . " and groupid='" . $groupid . "'")->order("OrdNo")->select(); return $list; } } //保存图文顺序 public function save_imgtext() { $post_data = I('tw/a'); $ordno = 1; foreach ($post_data as $k => $v) { $v['ordno'] = $ordno; //插入 M('wx_menulistdet')->where(array('id' => $k))->save($v); $ordno++; } return json(['status' => 1]); } //删除素材 public function del_material() { $model = M("wx_menulistdet"); $id = I('post.aid'); $model->where(array('id' => $id, 'store_id' => getAdmStoId()))->delete(); $return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',); $this->ajaxReturn($return_arr); } private function initEditor() { $this->assign("URL_upload", U('Admin/Ueditor/imageUp', array('savepath' => 'wechat'))); $this->assign("URL_fileUp", U('Admin/Ueditor/fileUp', array('savepath' => 'wechat'))); $this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp', array('savepath' => 'wechat'))); $this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage', array('savepath' => 'wechat'))); $this->assign("URL_imageManager", U('Admin/Ueditor/imageManager', array('savepath' => 'wechat'))); $this->assign("URL_imageUp", U('Admin/Ueditor/imageUp', array('savepath' => 'wechat'))); $this->assign("URL_getMovie", U('Admin/Ueditor/getMovie', array('savepath' => 'wechat'))); $this->assign("URL_Home", ""); } //选择图片 public function select_img() { return $this->fetch('', getAdmStoId()); } //关注二维码-列表/生成/删除 public function bulidewm() { $storeid = getAdmStoId(); $ajax = I('ajax'); $isdel = I('isdel'); $model = M("wx_ewmlist"); if ($ajax == '1') { $weixin_config = M('wx_user')->where('store_id=' . $storeid)->find(); //获取微信配置 $scene_id = I('scene_id'); if (empty($scene_id)) { $scene_id = ''; } $return = M('wx_ewmlist')->where(array('store_id' => $storeid, 'scene_id' => $scene_id))->find(); if (empty($return)) { //$access_token = $this->get_access_token($weixin_config['appid'], $weixin_config['appsecret']); $access_token = m_get_access_token($weixin_config,$storeid); if (!$access_token) { $this->error('获取access_token失败', U('Wechat/bulidewm')); // http://www.tpshop.com/index.php/Admin/Wechat/menu exit; } //获取数据的地址(微信提供) $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token; //发送给微信服务器的数据 if ($scene_id) { $jsonstr = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "' . $scene_id . '"}}}'; }else{ $jsonstr = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": "' . $scene_id . '"}}}'; } $return = httpRequest($url, 'POST', $jsonstr); $return = json_decode($return, 1); if (!empty($return['ticket'])) { $v['ticket'] = $return['ticket']; $v['store_id'] = $storeid; $v['scene_id'] = $scene_id; $v['date'] = time(); $v['loadurl'] = $return['url']; M('wx_ewmlist')->add($v); upload_ylp_log('B42生成二维码/生成'); $this->success('生成成功', U('Wechat/bulidewm')); exit; } else { // upload_ylp_log('生成二维码失败'); $this->error('生成失败', U('Wechat/bulidewm')); exit; } } else { // upload_ylp_log('当前识别码已有二维码'); $this->error('当前识别码已有二维码', U('Wechat/bulidewm')); exit; } } if ($isdel == '1')//删除 { $id = I('id/d'); //二维码ID $model->where(array('id' => $id, 'store_id' => getAdmStoId()))->delete(); // upload_ylp_log('删除二维码'); $this->success('删除成功', U('Wechat/bulidewm')); exit; } $keyword=I('keyword'); if ($keyword!="") { $keyword=urldecode(urldecode($keyword)); $this->assign('keyword', $keyword); $condition["a.scene_id|b.pickup_name"] = array('like','%'.$keyword.'%'); } $condition["store_id"] = $storeid; $count = $model->alias('a') ->join('(select pickup_id,pickup_no,pickup_name from wxd_pick_up where store_id='.$storeid.') b ','a.scene_id=b.pickup_no','left') ->where($condition)->count(); $page = new Page($count, 10); $userList = $model->alias('a') ->join('(select pickup_id,pickup_no,pickup_name from wxd_pick_up where store_id='.$storeid.') b ','a.scene_id=b.pickup_no','left') ->where($condition)->order('id') ->limit($page->firstRow . ',' . $page->listRows)->select(); $show = $page->show(); $this->assign('userList', $userList); $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $page); // upload_ylp_log('二维码列表'); return $this->fetch('', getAdmStoId()); } /** * 关键字回复列表 */ public function keyrepayList() { $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $model = M("wx_keyrepay"); $where = " 1=1 "; $keyword = I('keyword'); $getAdmStoId = getAdmStoId(); $where .= $keyword ? " and keyword like '%$keyword%' " : ""; $where .= " and store_id='" . $getAdmStoId . "'"; $count = $model->where($where)->count(); $Page = $pager = new Page($count, 10); $repayList = $model->where($where)->order("`id` asc")->limit($Page->firstRow . ',' . $Page->listRows)->select(); //var_dump($repayList); $show = $Page->show(); $this->assign('pager', $pager); $this->assign('show', $show); $this->assign('repayList', $repayList); $this->assign('pagenum', $pagenum); $this->assign('oldurl', urlencode(curPageURL())); // upload_ylp_log('关键字回复列表'); $this->assign('erpid', getERPId()); return $this->fetch('', getAdmStoId()); } /** * 添加修改关键字回复 */ public function AddEditRepay() { $id = I('id'); $result = 0; if (!empty($id)) { $info = M('wx_keyrepay')->where(array('store_id' => getAdmStoId(), 'id' => $id))->find(); } $ispost = I('ispost'); if ($ispost == 1) { $post_menu = $_POST;// input('post/a'); $v['wxdtype'] = $post_menu["hidtype"]; $v['value'] = $post_menu['hidvalue'];//str_replace('
', '\n', $post_menu['hidvalue']); //mlog($v['value'],'tt123'); //文字替换 $v['value']=str_replace('
', '
',$v['value']); $v['value']=str_replace('
', '', $v['value']); $v['media_id'] = $post_menu['hidmedia_id']; $v['store_id'] = getAdmStoId(); $v['keyword'] = $post_menu['MenuName']; if (empty($id)) { //插入 $v['sdate'] = time(); $result = M('wx_keyrepay')->add($v); // upload_ylp_log('新增关键字回复'); // $this->success('新增成功',U('Wechat/keyrepayList')); // exit; } else { //更新 // upload_ylp_log('更新关键字回复'); $result = M('wx_keyrepay')->where(array('id' => $id))->save($v); } if (empty($result)) { return json(['status' => 0]); } else { upload_ylp_log('B43关键字回复/保存'); return json(['status' => 1]); } } if (!empty($info)) { foreach ($info as $v) { if ($info['wxdtype'] == 'cont') { $info['value'] = preg_replace("/\r\n/", '
', $info['value']); } } } $this->assign('erpid', getERPId()); $this->assign('id', $id); $this->assign('info', $info); // upload_ylp_log('关键字回复详情'); return $this->fetch('', getAdmStoId()); } /** * 删除关键字回复 * 删除关键字回复 */ public function delkeyrepay() { $isshow = I('isshow'); $isdefault=I('isdefault'); $model = M("wx_keyrepay"); if (!empty($isshow)) { $v['isshow'] = $isshow; $model->where('id =' . $_GET['id'])->save($v); exit; } if (!empty($isdefault)) { if ($isdefault==2) { $v1['isdefault']=1; $model->where('store_id =' . getAdmStoId())->save($v1); } $v['isdefault'] = $isdefault; $model->where('id =' . $_GET['id'])->save($v); exit; } $model->where('id =' . $_GET['id'])->delete(); $return_arr = array('status' => 1, 'msg' => '操作成功', 'data' => '',); //$return_arr = array('status' => -1,'msg' => '删除失败','data' =>'',); // upload_ylp_log('删除关键字回复'); //$this->ajaxReturn($return_arr); return json_encode($return_arr); } public function check_zip($ind=0){ include_once "plugins/payment/weixin/weixin.class.php"; $wx=new \weixin(); $stoid=getAdmStoId(); $ordno=$total_fee=$refund_fee=1; $path=BASE_PATH.'public/cert/'.$stoid.'/'; $json=null; $json['time']=time(); try { $rs = $wx->refund2($ordno, $total_fee,$refund_fee, $path,$stoid); if($rs['return_code']=='FAIL'){ $json['code']=-1; $json['msg']=$rs['return_msg']; $str=urldecode(urldecode($rs['return_msg'])); if(strpos($str,'certificate not match')!==false){ $json['msg']="证书已失效,请到微信商户平台更新证书,重新下载后上传"; } if(strpos($str,'mch_id')!==false){ $json['msg']="微信支付商户号错误,请重新编辑"; } if(strpos($str,'签名错误')!==false){ $json['msg']="微信支付KEY错误,请重新编辑"; } if(strpos($str,'订单不存在')!==false){ $json['code']=1; $json['msg']='校验成功'; } }else{ $json['code']=1; $json['msg']='校验成功'; } }catch (\Exception $e) { $json['code']=1; $json['msg']='校验成功'; mlog($e->getMessage(),"check_zip/".getAdmStoId()); $str=$e->getMessage(); if(strpos($str,'52')!==false){ $json['code']=-1; $json['msg']='证书路径错误,请重新上传'; } } M('wx_user')->where('store_id',$stoid) ->save(['check_json'=>json_encode($json)]); if($ind==1) return $json; return json($json); } }