data = json_decode(file_get_contents('php://input'), true); $this->site_id=input('site_id',0); // $this->data = json_decode('{"eventId":"1162739761","timestamp":"1642841655","signature":"4d894d5b794c48701e312e173afdc08e0d4730a423ec3270e80b107214244e3e","orderId":"20201010164522464907","openId":"a2235c21ff2b207d039250fb06eeefbe","accountId":"101016452235","productId":8078,"appId":0,"resourceId":"","productInfo":{"productName":"\u5916\u5356\u8ba2\u9910\u70b9\u9910\u9884\u7ea6\u5c0f\u7a0b\u5e8f\u516c\u4f17\u53f7","isTrial":true,"spec":"productName","timeSpan":0,"timeUnit":"20190803100354","ccsDetail":null,"cycleNum":1},"extendInfo":{"comment":"xxxxxxx"},"action":"createInstance","extentBillingInfo":null,"requestId":"","type":"txcloud","site_id":"1"}', true); // var_dump(json_encode($this->data['productInfo'],JSON_UNESCAPED_UNICODE));die; // file_put_contents($this->data['action'].time().'.txt', file_get_contents('php://input') . PHP_EOL); // return ['info' => '未能处理结果', 'state' => 'fail']; //$json='{"eventId":"1828892141","timestamp":"1642838683","signature":"dde97aa5848c5e0123ee32d812805362224c0e8aff3f1147f2887ec608e5318e","echoback":"1642838683","action":"verifyInterface","requestId":"8ad4fc0f-30d1-40dd-ae33-6d8382508faf","type":"txcloud","site_id":"1"}'; // $this->data=json_decode('{"eventId":"597917031","timestamp":"1642849673","signature":"0181f659fe8a0498a2dbbf3d5b57e891423b30d6186d233e5e571a79bc258e0c","orderId":"20201010164522464907","signId":"dddd555","openId":"a2235c21ff2b207d039250fb06eeefbe","accountId":"101016452235","appId":0,"productId":8078,"resourceId":"","productInfo":null,"instanceExpireTime":"2022-05-06 00:00:00","extendInfo":null,"action":"renewInstance","extentBillingInfo":null,"requestId":"","type":"txcloud","site_id":"1"}',true); // $this->data=json_decode($json,true); // var_dump($this->data);die; if ($this->data) { if ($this->signVerify()) { switch ($this->data['action']) { case 'verifyInterface': //接入验证 $info = $this->verifyInterface(); break; case 'createInstance' : //创建新订单 $info = $this->createInstance(); break; case 'renewInstance' : //应用续费 $info = $this->renewInstance(); break; case 'modifyInstance' : //应用转正 $info = $this->modifyInstance(); break; case 'expireInstance' : //应用过期 $info = $this->expireInstance(); break; case 'destroyInstance' ://应用摧毁 $info = $this->destroyInstance(); break; default: return ['info' => '未能处理结果', 'state' => 'fail']; } return $info; } else { return ['info' => '签名不正确', 'state' => 'fail']; } } else { return ['info' => '未能处理结果', 'state' => 'fail']; } } /** * 创建新订单 */ public function createInstance() { $data = array(); $extendInfo=$this->data['extendInfo']??[]; $userCollectionInfo=$this->data['userCollectionInfo']??[]; $isTrial=$this->data['productInfo']['isTrial']==true?1:0; $data['site_id'] = $this->site_id; $data['order_id'] = $this->order_sn(); $data['type'] = 'txcloud'; $data['pay_type'] = 'txcloud'; $data['openid'] = $this->data['openId']; $data['third_order_id'] = $this->data['orderId']; $data['cloud_account'] = $this->data['accountId']??date('mdHis').rand(10,99); $data['apps_id'] = $this->order_sn('mdhi',11); $data['cloud_goods_id'] = $this->data['productId']; $data['requestId'] = $this->data['requestId']??''; $data['goods_name'] = $this->data['productInfo']['productName']??$this->data['productId']; $data['timeUnit'] = $this->data['productInfo']['timeUnit']??'d'; $data['is_trial'] = $isTrial; $data['order_number'] = $this->data['productInfo']['cycleNum']??1; $data['spec'] = $this->data['productInfo']['spec']??'微信小程序'; $data['timeSpan'] = $this->data['productInfo']['timeSpan']??7; $data['contact_name']=$userCollectionInfo['name']??''; $data['email'] = $userCollectionInfo['email']??''; $data['mobile'] = $userCollectionInfo['cellnumber']??''; $data['contact'] = json_encode($userCollectionInfo); $data['create_time'] = time(); $data['update_time'] = time(); $data['remarks'] = $extendInfo['comment']??json_encode($this->data); $data['raw_data'] = json_encode([$this->data]); $insert = Db::name('cloud_order')->insert($data); if ($insert) { $data['username']=$data['cloud_account']; $this->createShop($data); } $website_model = new WebsiteModel(); $agent_info=$website_model->getWebSite(['site_id'=>$this->site_id,'is_agent'=>1])['data']; $arr = array( 'signId' => $data['apps_id'], 'appInfo' => array( 'website' => $this->urls, 'authUrl' => $this->urls ), 'additionalInfo' => array( ['name' => '管理后台', 'value' => $this->urls.'/shop/login/login'], ['name' => '用户登录', 'value' => '您的账户:'.$data['username']." 默认密码:888888"], ['name' => '登录说明', 'value' => '首次登录请使用默认账户密码登录,登录成功登录后,可自行修改您的新密码'], ['name' => '温馨提示', 'value' => "温馨提示: 感谢购买SAAS应用服务,如需帮助请联系官网客服人员(联系电话:{$agent_info['web_phone']})"] ) ); if($agent_info['web_weixin']){ $arr['additionalInfo'][]=[ 'name' => '联系微信', 'value' => $agent_info['web_weixin'] ]; } return $arr; } /** *应用续费 */ public function renewInstance() { $data = array(); $extendInfo=$this->data['extendInfo']??[]; $userCollectionInfo=$this->data['userCollectionInfo']??[]; $isTrial=$this->data['productInfo']['isTrial']??0; $data['site_id'] = $this->site_id; $data['order_id'] = $this->order_sn(); $data['type'] = 'txcloud'; $data['pay_type'] = 'txcloud'; $data['openid'] = $this->data['openId']; $data['third_order_id'] = $this->data['orderId']; $data['cloud_account'] = $this->data['accountId']??date('mdHis').rand(10,99); $data['apps_id'] = $this->order_sn('mdhi',11); $data['cloud_goods_id'] = $this->data['productId']; $data['requestId'] = $this->data['requestId']??''; $data['goods_name'] = $this->data['productInfo']['productName']??$this->data['productId']; $data['timeUnit'] = $this->data['productInfo']['timeUnit']??'d'; $data['is_trial'] = $isTrial; $data['order_number'] = $this->data['productInfo']['cycleNum']??1; $data['spec'] = $this->data['productInfo']['spec']??'小程序'; $data['timeSpan'] = $this->data['productInfo']['timeSpan']??7; $data['contact_name']=$userCollectionInfo['name']??''; $data['email'] = $userCollectionInfo['email']??''; $data['mobile'] = $userCollectionInfo['cellnumber']??''; $data['contact'] = json_encode($userCollectionInfo); $data['create_time'] = time(); $data['update_time'] = time(); $data['expireTime'] = strtotime($this->data['instanceExpireTime']); $data['remarks'] = $extendInfo['comment']??json_encode($this->data); $data['raw_data'] = json_encode([$this->data]); $insert = Db::name('cloud_order')->insert($data); if ($insert) { $where = ['username' => $this->data['accountId'], 'site_type' => 'shop']; $shopInfo = Db::name('site')->where($where)->find(); if ($shopInfo) { model('site')->update([ 'expire_time'=>strtotime($this->data['instanceExpireTime']), 'is_try'=>0 ],$where); $count_time = intval(($data['expireTime'] - time()) / 86400); model('website')->setDec(['site_id' => $this->site_id], 'agent_number', $count_time); Cache::tag("website")->clear(); } else { $data['username'] = $data['cloud_account']; $this->createShop($data); } } $receipt = array('success' => true); return $receipt; } /** * 应用变更 转正 * */ public function modifyInstance() { $where = array( 'cloud_goods_id' => $this->data['productId'], 'apps_id' => $this->data['signId'], 'openid' => $this->data['openId'], 'is_trial' => '1' ); $order_info = Db::name('cloud_order')->where($where)->find(); if ($order_info) { $data = array(); $data['order_id'] = $this->order_sn(); $data['type'] = 'txcloud'; $data['openid'] = $this->data['openId']; $data['third_order_id'] = $this->data['orderId']; $data['cloud_account'] = @$order_info['accountId']; $data['cloud_goods_id'] = $this->data['productId']; $data['requestId'] = @$this->data['requestId']; $data['goods_name'] = $order_info['goods_name'].'--试用转正'; $data['timeUnit'] = $this->data['timeUnit']??'d'; $data['is_trial'] = 2; $data['spec'] = $this->data['spec']; $data['timeSpan'] = $this->data['timeSpan']??1; $data['mobile'] = @$this->data['mobile']; $data['email'] = @$this->data['email']; $data['apps_id'] = $this->data['signId']; $data['pay_type'] = 'txcloud'; $data['create_time'] = time(); $data['update_time'] = time(); $data['remarks'] = json_encode($this->data); $data['raw_data'] = json_encode([$this->data]); $insert = Db::name('cloud_order')->insert($data); $tiem=[ 'y'=>365, 'm'=>30, 'd'=>1, 'h'=>1, 't'=>1, ]; $expire_time=Time::daysAfter($tiem[$data['timeUnit']]*$data['timeSpan']); model('shop')->update(['expire_time'=>$expire_time],['username'=>$order_info['cloud_account']]); if ($insert) { $arr =[ 'success' => true, 'appInfo' => array( 'authUrl' => $this->urls ) ]; return $arr; } } else { $data = []; $data['order_id'] = $this->order_sn(); $data['goods_name'] = '腾讯云产品转正'; $data['type'] = 'txcloud'; $data['openid'] = $this->data['openId']; $data['third_order_id'] = $this->data['orderId']; $data['cloud_goods_id'] = $this->data['productId']; $data['cloud_account'] = @$order_info['accountId']; $data['requestId'] = @$this->data['requestId']; $data['is_trial'] = 2; $data['spec'] = $this->data['spec']; $data['timeSpan'] = $this->data['timeSpan']; $data['apps_id'] = $this->data['signId']; $data['pay_type'] = 'txcloud'; $data['create_time'] = time(); $data['update_time'] = time(); $data['remarks'] = json_encode($this->data); $data['raw_data'] = json_encode([$this->data]); $insert = Db::name('cloud_order')->insert($data); if ($insert) { $arr =[ 'success' => true, 'appInfo' => [ 'authUrl' => $this->urls ] ]; return $arr; } } } /** * 应用过期 */ public function expireInstance() { return array('success' => true); } /** * 应用注销 */ public function destroyInstance() { return array('success' => true); } /** * 接入验证 */ public function verifyInterface() { if ($this->data) { $data = [ 'echoback' => $this->data['echoback'] ]; return $data; } } /** * 验证签名 * @return bool */ public function signVerify() { $config=new Config(); $info=$config->getCloudConfig($this->site_id,'TXCLOUD_CONFIG')['data']['value']; $token = '1358DJPWcjqMvU4eEpPOPSWdkt2mXJlG'; //$info['token']??''; $params = array($token, input('timestamp'), input('eventId')); sort($params, SORT_STRING); $str = implode('', $params); if (input('signature') == hash('sha256', $str)) { return true; } else { return false; } } /** * 输出数类型 * @return string */ public function outFormat() { return 'json'; } }