| xqd
@@ -1833,7 +1833,7 @@ class AlbumController extends Controller
|
|
|
}
|
|
|
$weChatApp = AlbumManufacturerModel::where('store_id', $storeid)->first();//\Log::info('2221');
|
|
|
|
|
|
- $res_account = $this->accountMesage($g_open_id,$weChatApp,$name,$content);
|
|
|
+ $res_account = $this->accountMesage($open_id,$weChatApp,$name,$content);
|
|
|
\Log::info($weChatApp->wxFurniture_template_id);
|
|
|
\Log::info($user);
|
|
|
\Log::info($formId);
|
| xqd
@@ -1875,19 +1875,45 @@ class AlbumController extends Controller
|
|
|
*
|
|
|
* @return array|string
|
|
|
*/
|
|
|
- private function accountMesage($g_open_id,$weChatApp,$name,$content)
|
|
|
+ private function accountMesage($open_id,$weChatApp,$name,$content)
|
|
|
{
|
|
|
// Cache::flush();
|
|
|
- $value = Cache::get($g_open_id);
|
|
|
+ $value = Cache::get($open_id);
|
|
|
\Log::info($value);\Log::info('2225');
|
|
|
- if ($g_open_id && !empty($weChatApp->wxaccount_template_id) && (!$value || ($value + 60) <= time())) {
|
|
|
- Cache::put($g_open_id, time(), 1);
|
|
|
- $config = [
|
|
|
+ if ($open_id && !empty($weChatApp->wxaccount_template_id) && (!$value || ($value + 60) <= time())) {
|
|
|
+ Cache::put($open_id, time(), 1);
|
|
|
+ /* $config = [
|
|
|
'app_id' => $weChatApp->G_app_id,
|
|
|
'secret' => $weChatApp->G_app_secret,
|
|
|
'response_type' => 'array',
|
|
|
- ];
|
|
|
- $app = Factory::officialAccount($config);
|
|
|
+ ];*/
|
|
|
+
|
|
|
+ $ac = $this->getAccessToken($weChatApp);
|
|
|
+ $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" . $ac;
|
|
|
+ $date = date("Y-m-d H:i");
|
|
|
+ $page = "pages/sell/sell";
|
|
|
+ $data = array( "touser" => $open_id,
|
|
|
+ "mp_template_msg" => array(
|
|
|
+ "appid" => $weChatApp->G_app_id,
|
|
|
+ "url" => "http://weixin.qq.com/download",
|
|
|
+ "template_id" => $weChatApp->wxaccount_template_id,
|
|
|
+ "miniprogram" => array(
|
|
|
+ "appid" => $weChatApp->app_id,
|
|
|
+ "pagepath" => $page
|
|
|
+ ),
|
|
|
+ "data" => array(
|
|
|
+ "first" => array( "value" => "您有未读消息!", "color" => "#c27ba0" ),
|
|
|
+ "keyword1" => array( "value" => $name, "color" => "#93c47d" ),
|
|
|
+ "keyword2" => array( "value" => $content, "color" => "#0000ff" ),
|
|
|
+ "keyword3" => array( "value" => $date, "color" => "#0000ff" ),
|
|
|
+ // "remark" => array( "value" => $date, "color" => "#45818e" )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
|
+ $res = $this->curlPost($url, $data);
|
|
|
+ $res = json_decode($res, true);
|
|
|
+ /* $app = Factory::officialAccount($config);
|
|
|
$res = $app->template_message->send([
|
|
|
'touser' => $g_open_id,
|
|
|
'template_id' => $weChatApp->wxaccount_template_id,
|
| xqd
@@ -1901,13 +1927,43 @@ class AlbumController extends Controller
|
|
|
'appid' => $weChatApp->app_id,
|
|
|
'pagepath' => 'pages/sell/sell'
|
|
|
],
|
|
|
- ]);
|
|
|
+ ]);*/
|
|
|
return $res;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ protected function curlPost($url, $data)
|
|
|
+ {
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 1);
|
|
|
+ $output = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ return $output;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getAccessToken($app)
|
|
|
+ {
|
|
|
+ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $app->app_id . "&secret=" . $app->app_secret;
|
|
|
+ $data = $this->curlGet($url);
|
|
|
+ $data = json_decode($data["content"], true);
|
|
|
+ if( !isset($data["access_token"]) )
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $access_token = $data["access_token"];
|
|
|
+ return $access_token;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @api {get} /api/album/add_agent 申请经销商(add_agent)
|
|
|
* @apiDescription 申请经销商(add_agent)
|