<?php
/**
* 企业小程序模块小程序接口定义
*
* @auth or w-w-w-.-e-f-w-w-w-.-c-o-m
* @url
*/
defined('IN_IA') or exit('Access Denied');
class Weixinmao_houseModuleWxapp extends WeModuleWxapp {
public function GetSiteUrl()
{
global $_GPC, $_W;
if($_W['attachurl']!=""){
$siteurl = $_W['attachurl'];
}else{
$siteurl = $_W['siteroot'].'attachment/';
}
return $siteurl;
}
public function IsCheck()
{
global $_GPC, $_W;
$intro = pdo_fetch("SELECT ischeck FROM " . tablename('weixinmao_house_intro')." WHERE uniacid=:uniacid",array(":uniacid" => $_W['uniacid']));
return $intro['ischeck'];
}
public function IsAgent()
{
global $_GPC, $_W;
$intro = pdo_fetch("SELECT isagent FROM " . tablename('weixinmao_house_intro')." WHERE uniacid=:uniacid",array(":uniacid" => $_W['uniacid']));
return $intro['isagent'];
}
public function IsCheck2()
{
global $_GPC, $_W;
$intro = pdo_fetch("SELECT ischeck2 FROM " . tablename('weixinmao_house_intro')." WHERE uniacid=:uniacid",array(":uniacid" => $_W['uniacid']));
return $intro['ischeck2'];
}
public function doPageTalk(){
global $_GPC, $_W;
$token = 'abc123abc';
//echo $token;
$echoStr = $_GET["echostr"];
$this->responseMsg();
if ($this->checkSignature($token)) {
echo $echoStr;
exit;
}
}
public function checkSignature($token) //官方的验证函数
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = $token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function responseMsg()
{
$fromUsername = $postArr['FromUserName']; //发送者openid
$content = '您好,有什么能帮助你?';
$data=array(
"touser"=>$fromUsername,
"msgtype"=>"text",
"text"=>array("content"=>$content)
);
$json = json_encode($data,JSON_UNESCAPED_UNICODE); //php5.4+
$access_token = $this->get_accessToken();
/*
* POST发送https请求客服接口api
*/
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token;
//以'json'格式发送post的https请求
error_reporting(0);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($json)){
curl_setopt($curl, CURLOPT_POSTFIELDS,$json);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers );
$output = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Errno'.curl_error($curl);//捕抓异常
}
curl_close($curl);
if($output == 0){
echo 'success';exit;
}
}
public function doPagedelSaleinfo(){
global $_GPC, $_W;
$id = $_GPC['id'];
pdo_delete('weixinmao_house_saleinfo', array('id' => $id));
return $this->result(0, 'success', $list);
}
public function doPagedelSaleinfo2(){
global $_GPC, $_W;
$id = $_GPC['id'];
$sessionid = $_GPC['sessionid'];
$ordertype = $_GPC['ordertype']? $_GPC['ordertype'] : 1;
if($ordertype == 1)
// $condition = " type = 1 AND ";
$saletable = 'weixinmao_house_saleinfo';
elseif($ordertype == 2)
//$condition = " type = 2 AND ";
$saletable = 'weixinmao_house_carsaleinfo';
elseif($ordertype == 3)
// $condition = " type = 3 AND ";
$saletable = 'weixinmao_house_shopsaleinfo';
elseif($ordertype == 4)
//$condition = " type = 4 AND ";
$saletable = 'weixinmao_house_buesaleinfo';
pdo_delete($saletable, array('id' => $id));
return $this->result(0, 'success', $list);
}
public function doPagedelOldhouseinfo(){
global $_GPC, $_W;
$id = $_GPC['id'];
pdo_delete('weixinmao_house_oldhouseinfo', array('id' => $id));
return $this->result(0, 'success', $list);
}
public function doPagedelLethouseinfo()
{
global $_GPC, $_W;
$id = $_GPC['id'];
pdo_delete('weixinmao_house_lethouseinfo', array('id' => $id));
return $this->result(0, 'success', $list);
}
public function doPageGetcity()
{
global $_GPC, $_W;
$sql = 'SELECT * FROM ' . tablename('weixinmao_house_area') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
$arealist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
return $this->result(0, 'success', $arealist);
}
public function httpGet($url) {
error_reporting(0);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
public function doPageGetphone()
{
global $_GPC, $_W;
include "inc/wxBizDataCrypt.php";
//var_dump($is);
// $code = $_GET['code'];
$iv = $_GPC['iv'];
$encryptedData = $_GPC['encryptedData'];
$appid = $_W['uniaccount']['key'];;//小程序唯一标识 (在微信小程序管理后台获取)
$appsecret = $_W['uniaccount']['secret'];//小程序的 app secret (在微信小程序管理后台获取)
// $grant_type = "authorization_code"; //授权(必填)
// $params = "appid=".$appid."&secret=".$appsecret."&js_code=".$code."&grant_type=".$grant_type;
// $url = "https://api.weixin.qq.com/sns/jscode2session?".$params;
// $res = json_decode($this->httpGet($url),true);
//json_decode不加参数true,转成的就不是array,而是对象。 下面的的取值会报错 Fatal error: Cannot use object of type stdClass as array in
// $sessionKey = $res['session_key'];//取出json里对应的值
//echo $_SESSION['session_key'];
$pc = new WXBizDataCrypt($appid, $_SESSION['session_key']);
// var_dump($pc);
// echo $encryptedData, $iv;
$errCode = $pc->decryptData($encryptedData, $iv, $data);
$obj = json_decode($data);
$uid = $_GPC['uid'];
$tel = $obj->phoneNumber;
// echo $tel;
pdo_update('weixinmao_house_userinfo',array('tel'=>$tel),array('uid'=>$uid));
return $this->result(0, 'success', array());
}
public function doPageGetcitylist()
{
global $_GPC, $_W;
$condition_hot = " WHERE ishot = 1 AND uniacid=:uniacid ORDER BY sort DESC ";
$sql = 'SELECT id ,name FROM ' . tablename('weixinmao_house_city') . $condition_hot ;
$hotlist = pdo_fetchall($sql,array(":uniacid" => $_W['uniacid']));
$condition = " WHERE uniacid=:uniacid GROUP BY firstname ORDER BY firstname ,sort DESC";
$sql = 'SELECT firstname FROM ' . tablename('weixinmao_house_city') . $condition ;
$firstnamelist = pdo_fetchall($sql,array(":uniacid" => $_W['uniacid']));
$conditionlist = " WHERE uniacid=:uniacid AND firstname=:firstname ";
$sql = 'SELECT id ,name FROM ' . tablename('weixinmao_house_city') . $conditionlist ;
foreach($firstnamelist AS $k=>$v)
{
$list = pdo_fetchall($sql,array(":uniacid" => $_W['uniacid'],':firstname'=>$v['firstname']));
$firstnamelist[$k]['firstli