merchantId);
$wxMenuOptionList = configDict::getConfig('wxMenuOption');
$replyTypeList = configDict::getConfig('replyType');
$wxMenuOptionName = configDict::getConfig('wxMenuOptionName');
$active = xhActive::find()->where(['merchantId' => $this->merchantId])->orderBy('id desc')->limit(5)->all();
return $this->render('menu', ['active' => $active, 'menu' => $wxMenu, 'wxMenuOptionName' => $wxMenuOptionName, 'wxMenuOptionList' => $wxMenuOptionList, 'replyTypeList' => $replyTypeList, 'merchant' => $this->merchant, 'commonUseUrl' => $commonUseUrl, 'manageStyle' => $manageStyle]);
}
/**
* 更新到数据库;提交
*/
public function actionReplaceMenu()
{
xhWxMenuService::delMenuList($this->merchantId);
$now = time();
$date = date("Y-m-d H:i:s", $now);
$post = Yii::$app->request->post();
$submitToWx = isset($post['submitToWx']) ? $post['submitToWx'] : '';
$level1String = isset($post['level1String']) ? $post['level1String'] : '';
$level2String = isset($post['level2String']) ? $post['level2String'] : '';
$level1String = rtrim($level1String, '◆◆');
$level1 = explode('◆◆', $level1String);
$commonUseUrl = configDict::getConfig('commonUseUrl');
$parentIdList = [];//记录一级菜单的数据库id
foreach ($level1 as $key => $val) {//一级菜单数据整理
$arr = explode('◇◇', $val);
$menuOrder = $arr[0];//一级菜单序号
$wxMenuOption = $arr[3];//选项
$wxMenuContent = $arr[4];//内容
$addData = [];
$addData['parentId'] = 0;
$addData['merchantId'] = $this->merchantId;
$addData['menuOrder'] = $menuOrder;
$addData['menuOption'] = $wxMenuOption;
$addData['hasSonMenu'] = $arr[1];
$addData['name'] = $arr[2];
$addData['menuKey'] = $this->merchantId . '_' . $menuOrder;
$addData['createTime'] = $date;
$addData['replyType'] = $arr[5];
if (!empty($wxMenuContent)) {
$formatData = xhWxMenuService::getFormatData($wxMenuContent, $wxMenuOption, $this->merchant);
$addData = array_merge($addData, $formatData);
}
$return = xhWxMenuService::add($addData);
$parentIdList[$menuOrder] = $return['id'];
}
if (!empty($level2String)) {
$level2String = rtrim($level2String, '◆◆');
$level2 = explode('◆◆', $level2String);
foreach ($level2 as $key => $val) {//二级菜单数据整理
$arr = explode('◇◇', $val);
$menuOrder = $arr[0];
$parentMenuOrder = $arr[1];
$wxMenuOption = $arr[3];
$wxMenuContent = $arr[4];
$addData['parentId'] = $parentIdList[$parentMenuOrder];
$addData['merchantId'] = $this->merchantId;
$addData['menuOrder'] = $menuOrder;
$addData['menuOption'] = $wxMenuOption;
$addData['name'] = $arr[2];
$addData['menuKey'] = $this->merchantId . '_' . $parentMenuOrder . '_' . $menuOrder;
$addData['createTime'] = $date;
$addData['replyType'] = $arr[5];
if (!empty($wxMenuContent)) {
$formatData = xhWxMenuService::getFormatData($wxMenuContent, $wxMenuOption, $this->merchant);
$addData = array_merge($addData, $formatData);
}
xhWxMenuService::add($addData);
}
}
if (empty($submitToWx)) {
util::successInfo();
}
$wxMenu = xhWxMenuService::getMenuList($this->merchantId);
if (empty($wxMenu)) {
util::failInfo();
}
$replyType = configDict::getConfig('replyType');
$menuData = [];
foreach ($wxMenu as $wxKey => $wxVal) {
$child = $wxVal['child'];
if (!empty($child)) {
$menuData[$wxKey] = ['type' => 'view', 'name' => $wxVal['name']];
foreach ($child as $chKey => $chVal) {
if ($chVal['replyType'] == $replyType['redirectUrl']) {
$menuData[$wxKey]['sub_button'][$chKey] = ['type' => 'view', 'name' => $chVal['name'], 'url' => $chVal['replyUrl']];
} else {
$menuData[$wxKey]['sub_button'][$chKey] = ['type' => 'click', 'name' => $chVal['name'], 'key' => $chVal['menuKey']];
}
}
} else {
if ($wxVal['replyType'] == $replyType['redirectUrl']) {
$menuData[$wxKey] = ['type' => 'view', 'name' => $wxVal['name'], 'url' => $wxVal['replyUrl']];
} else {
$menuData[$wxKey] = ['type' => 'click', 'name' => $wxVal['name'], 'key' => $wxVal['menuKey']];
}
}
}
$subData['button'] = $menuData;
$weixinUtil = new weixinUtil($this->merchant);
$json = $weixinUtil->userMenuToWeiXin($subData);
$r = json_decode($json, true);
if ($r['errcode'] == 0) {
util::successInfo('操作成功,5分钟后生效');
}
util::successInfo('发布失败');
}
public function actionGetMediaId()
{
$wx = weixinUtil::batchgetMaterial($this->merchant, ['type' => 'image', 'offset' => 0, 'count' => 100]);
dump($wx);
$wx = weixinUtil::batchgetMaterial($this->merchant, ['type' => 'video', 'offset' => 0, 'count' => 100]);
dump($wx);
}
public function actionGetMaterial()
{
$access_token = $accessToken = weixinUtil::getAuthorizerAccessToken($this->merchant);
$material = new material();
$result = $material->getTotal($access_token);
dump($result);
dump($this->merchant);
$data = ['type' => 'video', 'offset' => 0, 'count' => 100];
$weixinUtil = new weixinUtil($this->merchant);
$videoIdList = $weixinUtil->batchgetMaterial($this->merchant, $data);
dump($videoIdList);
return;
}
public function actionUpVideo()
{
return $this->render('upVideo');
}
public function actionDoUp()
{
/*$weixinUtil = new weixinUtil();
$rootPath = dirname(Yii::$app->BasePath);
dump($rootPath);
$fileData['media'] = $rootPath.'/yfx.mp4';
$jsonData = ["title"=>'雨菲轩', "introduction"=>'6666'];
$fileData = $rootPath.'/yfx.mp4';
$json = $weixinUtil->uploadVideoMedia($this->merchant, $fileData);
dump($fileData);
dump($json);*/
$access_token = weixinUtil::getAuthorizerAccessToken($this->merchant);
$rootPath = dirname(Yii::$app->BasePath);
$material = new material();
/*
$fileData = $rootPath.'/yfx.mp4';
$result = $material->uploadVideo($access_token, $fileData,"测试上传");
dump($result);*/
/*$jpgFile = $rootPath.'/images/uploads/201703/29/jpg/17032922644_43.jpg';
$result =$material->uploadImage($access_token, $jpgFile);
dump($result);*/
//上传临时素材
$video = $rootPath . '/yfx.mp4';
$media = new media();
$re = $media->upload($access_token, 'video', $video);
dump($re);
}
/**
* 模拟测试 微信门店审批(不要删除)
*/
public function actionPostXml()
{
//fail succ
// Do a POST
$xml = "
1408622107
";
$url = "http://o.zhhinc.com/wx/api";
//取开放平台信息
$openId = configDict::getConfig('openId');
$open = xhWxOpenService::getById($openId);
$encodingAesKey = $open['aesKey'];
$openToken = $open['token'];
$openAppId = $open['appId'];
$timeStamp = isset($get['timestamp']) ? $get['timestamp'] : '';
$nonce = isset($get['nonce']) ? $get['nonce'] : '';
$pc = new \WxCrypt\WXBizMsgCrypt($openToken, $encodingAesKey, $openAppId);
$encryptMsg = '';
$errCode = $pc->encryptMsg($xml, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
//print("加密后: " . $encryptMsg . "\n");
$header[] = "Content-type: text/xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encryptMsg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
if (curl_errno($ch)) {
dump($ch);
}
curl_close($ch);
} else {
print($errCode . "\n");
}
print("加密后: " . $encryptMsg . "\n");
/*$url = "http://a.zhhinc.com/wx/api";
$curl = new curl\Curl();
$result = $curl->setOption(CURLOPT_POSTFIELDS,Json::encode($xml))->post($url);
$result = Json::decode($result);
dump($result);*/
//解密
/*$xml_tree = new \DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
$format = "";
$from_xml = sprintf($format, $encrypt);
// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
print("解密后: " . $msg . "\n");
$postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA );
dump($postObj);
} else {
print($errCode . "\n");
}*/
}
/**
* 第三方发送消息给公众平台
* 第三方收到公众号平台发送的消息
*/
public function actionDemo()
{
// 第三方发送消息给公众平台
$encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";
$token = "pamtest";
$timeStamp = "1409304348";
$nonce = "xxxxxx";
$appId = "wxb11529c136998cb6";
$text = "1407743423";
$pc = new \WxCrypt\WXBizMsgCrypt($token, $encodingAesKey, $appId);
$encryptMsg = '';
$errCode = $pc->encryptMsg($text, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
print("加密后: " . $encryptMsg . "\n");
} else {
print($errCode . "\n");
}
$xml_tree = new \DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
$format = "";
$from_xml = sprintf($format, $encrypt);
// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
print("解密后: " . $msg . "\n");
$postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
dump($postObj);
} else {
print($errCode . "\n");
}
}
/**
* 删除菜单
*/
public function actionMenuDel()
{
$return = weixinUtil::menuDelete($this->merchant);
dump($return);
}
}