rabbitmq->getProducer('producers'); $msg = serialize(['dataset_id' => rand(1, 100), 'linked_datasets' => []]); $producer->publish($msg, 'ex1', 'route1'); echo 'ok'; } public function actionBindOpen() { $merchant = $this->merchant; $wxAppId = $merchant['wxAppId']; $miniAppId = $merchant['miniAppId']; $open_appid = $merchant['openAppId']; echo "
";
		
		$id = Yii::$app->request->get('id', 0);
		//创建平台,并将公众号绑定到平台
		if ($id == 1) {
			weixinUtil::createOpenAccount($wxAppId, $this->merchant);
			$return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
			print_r($return);
			if ($return['errcode'] == 0) {
				$openAppId = $return['open_appid'];
				xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
			}
		}
		//将小程序绑定到平台
		if ($id == 2) {
			$openAppId = $merchant['openAppId'];
			$r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
			print_r($r);
		}
		//查询公众号 小程序的绑定情况
		if ($id == 3) {
			$return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
			print_r($return);
			$return = weixinUtil::getOpenAccount($miniAppId, $this->merchant, true);
			print_r($return);
		}
		
		//设置小程序服务器域名
		if ($id == 4) {
			weixinUtil::setDomain($this->merchant);
			weixinUtil::setWebViewDomain($this->merchant);
		}
		
		//为授权的小程序帐号上传小程序代码
		if ($id == 5) {
			$tId = $_GET['tId'];
			weixinUtil::miniCommit($this->merchant, $tId);
		}
		
		//获取小程序体验码
		if ($id == 6) {
			weixinUtil::getExperienceQrCode($this->merchant);
		}
		
		//获取授权小程序帐号已设置的类目
		if ($id == 7) {
			weixinUtil::getMiniCategory($this->merchant);
		}
		
		//获取小程序的第三方提交代码的页面配置
		if ($id == 8) {
			weixinUtil::getMiniPage($this->merchant);
		}
		
		//将第三方提交的代码包提交审核
		if ($id == 9) {
			weixinUtil::miniSubmitAudit($this->merchant);
		}
		
		//查询最新一次提交的审核状态
		if ($id == 10) {
			weixinUtil::miniGetLatestAuditStatus($this->merchant);
		}
		
		//发布已通过审核的小程序
		if ($id == 11) {
			weixinUtil::miniRelease($this->merchant);
		}
		
		//撤回审核
		if ($id == 12) {
			weixinUtil::rollbackCheck($this->merchant);
		}
		//生成 申请会员页 的小程序码
		if ($id == 13) {
			weixinUtil::generateMemberCode($this->merchant);
		}
		//解绑小程序和公众号绑定的平台
		if ($id == 14) {
			weixinUtil::unbindAccount($this->merchant);
			weixinUtil::unbindMiniProgram($this->merchant);
		}
		Yii::$app->end();

		$r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true);
		print_r($r);
		echo $miniAppId . ' ' . $open_appid . ' ';
		
		$return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
		print_r($return);
		die;
		
		$return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
		print_r($return);
		die;
		
		$r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
		print_r($r);
		echo $miniAppId . ' ' . $open_appid . ' ';
		
		$return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
		print_r($return);
		$return = weixinUtil::getOpenAccount($miniAppId, $this->merchant);
		print_r($return);
		die;
		
		if ($return['errcode'] == 0) {
			$open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
		} else {
			$return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
			if ($return['errcode'] == 0) {
				$open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
			}
		}
		echo "
open_appid:" . $open_appid . "
"; if (!empty($open_appid)) { xhMerchantService::updateById($this->merchantId, ['openAppId' => $open_appid]); $r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant); echo "绑定小程序结果:
"; print_r($r); } echo "

"; $return = weixinUtil::getOpenAccount($wxAppId, $merchant); echo "微信appId:{$wxAppId}
"; print_r($return); $return = weixinUtil::getOpenAccount($miniAppId, $merchant); echo "
小程序appId:{$miniAppId}
"; print_r($return); } public function actionCs() { // 忽略获取的header数据 $ignore = ['host', 'accept', 'content-length', 'content-type']; $headers = []; foreach ($_SERVER as $key => $value) { if (substr($key, 0, 5) === 'HTTP_') { $key = substr($key, 5); $key = str_replace('_', ' ', $key); $key = str_replace(' ', '-', $key); $key = strtolower($key); if (!in_array($key, $ignore)) { $headers[$key] = $value; } } } $token = isset($headers['token']) ? $headers['token'] : ''; } public function actionIndex() { echo 'aaa';die; $time = strtotime(date("Y-m-d")); $todayIncome = xhStatIncomeService::getTodayIncome($this->merchantId, $time); $year = date("Y"); $month = date("n"); $monthIncome = xhStatIncomeMonthService::getMonthIncome($this->merchantId, $year, $month); $statUser = StatUserByDayService::getTodayNum(); $todayVisit = VisitByDayService::getTodayNum($this->merchantId); $totalVisit = VisitByDayService::getTotalVisit($this->merchantId); $latestIncome = xhStatIncomeService::getLatestIncome($this->merchantId);//取最近10天的收入 $dayIncome = xhStatIncome::find()->where(['merchantId' => $this->merchantId])->asArray()->orderBy('time desc')->limit(3)->all(); $income = StatIncomeService::getTodayNum(); //获取最近的订单 shish 2019.8.19 $orderList = OrderService::getLatestOrder(); //今日访问量 $todayVisitNum = VisitByDayService::getTodayNum($this->merchantId); return $this->render('index', [ 'merchant' => $this->merchant, 'merchantExtend' => $this->merchantExtend, 'merchantAsset' => $this->merchantAsset, 'todayIncome' => $todayIncome, 'monthIncome' => $monthIncome, 'statUser' => $statUser, 'todayVisit' => $todayVisit, 'totalVisit' => $totalVisit, 'latestIncome' => $latestIncome, 'dayIncome' => $dayIncome, 'orderList' => $orderList, 'income' => $income, 'todayVisitNum' => $todayVisitNum, ]); } public function actionTest() { } public function actionLogin() { $merchant = xhMerchantService::getById(12358); $data = ["touser" => 'oTFbYvsjwgVwXggwtlM2ESAKwuN8', "template_id" => 'rxcSb6up1IgKJQY2XcTodJdFweigTu6UPXVZ7wsdWcI', "url" => 'http://m.huaml.com/order/detail?id=1', "data" => [ "first" => ["value" => '石头付款', "color" => "#173177"], "keyword1" => ["value" => '10元', "color" => "#173177"], "keyword2" => ["value" => '客户付款', "color" => "#173177"], "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"], "remark" => ["value" => "点击查看明细", "color" => "#173177"]]]; $accessToken = weixinUtil::getAuthorizerAccessToken($merchant); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accessToken}"; //$data = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE)); //$curl = new curl\Curl(); //$response = $curl->setOption(CURLOPT_POSTFIELDS, $data)->post($url); //self::asyncRequest('https://api.weixin.qq.com','/cgi-bin/message/template/send?access_token='.$accessToken,json_encode($data, JSON_UNESCAPED_UNICODE)); //echo 'ok'; //die; $params = json_encode($data,JSON_UNESCAPED_UNICODE); $start_time = microtime(true); $fp = fsockopen('ssl://api.weixin.qq.com', 443, $error, $errstr, 3); $http = "POST /cgi-bin/message/template/send?access_token={$accessToken} HTTP/1.1\r\nHost: api.weixin.qq.com\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($params) . "\r\nConnection:close\r\n\r\n$params\r\n\r\n"; fwrite($fp, $http); fclose($fp); die; sleep(3); Yii::info('id:'.$_POST['name']); util::ok(); if ($this->isLogin) { $this->redirect(['main/index']); } return $this->renderPartial('login'); } private static function asyncRequest($host, $path, $param = []){ $query = isset($param) ? http_build_query($param) : ''; $port = 80; $errno = 0; $errstr = ''; $timeout = 30; //连接超时时间(S) $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); //$fp = stream_socket_client("tcp://".$host.":".$port, $errno, $errstr, $timeout); if (!$fp) { return '连接失败'; } if ($errno || !$fp) { return $errstr; } stream_set_blocking($fp,0); //非阻塞 stream_set_timeout($fp, 1);//响应超时时间(S) $out = "POST " . $path . " HTTP/1.1\r\n"; $out .= "host:" . $host . "\r\n"; $out .= "content-length:" . strlen($query) . "\r\n"; $out .= "content-type:application/x-www-form-urlencoded\r\n"; $out .= "connection:close\r\n\r\n"; $out .= $query; $result = @fputs($fp, $out); @fclose($fp); return $result; } /** * 重复登陆,记录登陆名 * @return string */ public function actionRelogin() { return $this->renderPartial('relogin'); } public function actionLogout() { xhAdminService::logout(); $this->redirect(['main/login']); } public function actionCheckLogin() { $request = Yii::$app->request; $mobile = $request->post('mobile'); $password = $request->post('password'); $return = xhAdminService::loginByMobile($mobile, $password, true);//true 自动登陆 util::encode($return); } public function actionSetLoginPassword() { $id = $this->adminId; $admin = xhAdminService::getById($id); return $this->render('setLoginPassword', ['admin' => $admin]); } public function actionModifyLoginPassword() { $post = Yii::$app->request->post(); $prePassword = isset($post['prePassword']) ? $post['prePassword'] : ''; $id = $this->adminId; $admin = xhAdminService::getById($id); $savePwd = $admin['password']; if (empty($savePwd)) { util::failInfo('请填写密码'); } if (md5($prePassword) == $savePwd) { util::failInfo('原密码不正确'); } xhAdminService::updateById($id, ['password' => md5($post['password'])]); util::successInfo('修改成功'); } /** * 扫码枪扫码 */ public function actionSearch() { $get = Yii::$app->request->get(); $content = isset($get['content']) ? $get['content'] : ''; $id = preg_replace('/\D/s', '', $content); if (strpos($content, configDict::getQrKey('user')) === 0) { $this->redirect(['/user/detail', 'id' => $id]); Yii::$app->end(); } if (strpos($content, configDict::getQrKey('coupon')) === 0) { $this->redirect(['/coupon/detail', 'id' => $id]); Yii::$app->end(); } } /** * 审核通过 */ public function actionApprove() { $openMerchant = xhWxOpenService::getMerchant(); return $this->render('approve', ['admin' => $this->admin, 'openMerchant' => $openMerchant]); } public function actionQuickOrder() { $this->redirect(Yii::$app->params['frontUrl'] . '/payment/quick-order?account=' . $this->merchant['id']); } public function actionPub() { $channelName = 'redis_shi'; $time = time(); Yii::$app->redis->executeCommand('PUBLISH', [$channelName, $time]); } public function actionSub() { $channelName = 'redis_shi'; print_r(Yii::$app->redis->executeCommand('SUBSCRIBE', [$channelName])); } public function actionError() { $msg = Yii::$app->request->get('msg'); return $this->render('error', ['msg' => $msg]); } }