1. 程式人生 > >微信公眾號程式碼推送

微信公眾號程式碼推送

model

public function cashOutPush($accountID,$userID){
$user = Db::table("user_info")->where("userID",$userID)->find();
$account = Db::table("user_account")->where("accountID",$accountID)->find();
$userInfo = Db::table("user_info")->where("isManager",1)->select();
$title = "有新的提現申請
"; $content= " 提現申請:".$user["nick"]." 提現金額:".$account["amount"]."申請時間:".date("Y-m-d",$account["estTime"])." "; $url = Config::get("url")."index/Account/cashAccept"; $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.Config::get("APPID").'&redirect_uri='.$url.'&response_type=code&scope=snsapi_base&state=netvii#wechat_redirect'
; foreach($userInfo as $k=>$v){ sendImgText($v["openID"],$title,$content,$url,""); } }
controller1
function sendImgText($openID,$title,$content,$url,$img){ //推送單圖文客服訊息
$arr = array();
$msg  = '{
           "touser":"'.$openID.'",
           "msgtype":"news",
           "news":{
"articles":[{ "title":"'.$title.'", "description":"'.$content.'", "url":"'.$url.'", "picurl":"'.$img.'" }] } }'; array_push($arr,$msg); return sendMsg($arr); }
function sendMsg($data){ //傳送客服訊息
$token = getToken();
for($i=0;$i<count($data);$i++){
$json = stripslashes($data[$i]);
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
$tmpInfo = myCurl($url,$json);
    }
return $tmpInfo;
}

controller2
$pushModel = new PushModel();
$pushModel->cashOutPush($cashAccountID,Session::get("userInfo.userID"));
推送多圖文:
public function firstPush($userID){
$userInfo = db("user_info")->where("userID=".$userID)->find();
$openID = $userInfo["openID"];
$title1 = "歡迎關注永康基因";
$title2 = "瞭解自己";
$title3 = "申請代理";
$content1 = "";
$content2 = "";
$content3 = "";
$url1 = "";
$url2 = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.Config::get("APPID").'&redirect_uri='.Config::get("url").'index/Dnagenenew/gene&response_type=code&scope=snsapi_base&state=netvii#wechat_redirect';
$url3 = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.Config::get("APPID").'&redirect_uri='.Config::get("url").'index/Dnaagentnew/agent&response_type=code&scope=snsapi_base&state=netvii#wechat_redirect';
$img1 = Config::get("image")."gene.jpg";
$img2 = Config::get("image")."gene4.jpg";
$img3 = Config::get("image")."agent.png";
$arr = array();
$msg  = '{
       "touser":"'.$openID.'",
       "msgtype":"news",
       "news":{
              "articles":[{
                     "title":"'.$title1.'",
                     "description":"'.$content1.'",
                     "url":"'.$url1.'",
                     "picurl":"'.$img1.'"
               },
               {
                     "title":"'.$title2.'",
                     "description":"'.$content2.'",
                     "url":"'.$url2.'",
                     "picurl":"'.$img2.'"
               },
               {
                     "title":"'.$title3.'",
                     "description":"'.$content3.'",
                     "url":"'.$url3.'",
                     "picurl":"'.$img3.'"
               }
               ]
        }
        }';
array_push($arr,$msg);
return sendMsg($arr);
}