云迈博客

您现在的位置是:首页 > 其他 > 正文

其他

微信公众号关注推送图文消息

刘琦2022-07-31其他15
1.配置公众号的服务器配置functionweixin_action(){$json=file_get_contents('php://input');

1.配置公众号的服务器配置

function weixin_action(){
        $json = file_get_contents('php://input');
        $to_array = $this->xml_to_array($json);
        $signin->insert("sendsms_log",$data);
       if ($array['Event'] == "subscribe"){
           $this->subscribe($array);
       }
    }
function subscribe($array){
        $FromUserName = $array['FromUserName'];
        $ToUserName = $array['ToUserName'];
        $centent ="你好欢迎关注";
        $timeStamp = time();
//        $text = "<xml><ToUserName><![CDATA[$FromUserName]]></ToUserName><FromUserName><![CDATA[$ToUserName]]></FromUserName><CreateTime>$timeStamp</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[$centent]]></Content></xml>";
        $centent = "点击向云迈投递你的简历";
        $text ="<xml>
  <ToUserName><![CDATA[$FromUserName]]></ToUserName>
  <FromUserName><![CDATA[$ToUserName]]></FromUserName>
  <CreateTime>$timeStamp</CreateTime>
  <MsgType><![CDATA[news]]></MsgType>
  <ArticleCount>1</ArticleCount>
  <Articles>
    <item>
      <Title><![CDATA[$centent]]></Title>
      <Description><![CDATA[欢迎你加入我们]]></Description>
      <PicUrl><![CDATA[https://zhipin.blzphr.com/data/logo/20220530/16547433743.jpg]]></PicUrl>
      <Url><![CDATA[https://zhipin.blzphr.com/wap/index.php?c=company&a=showcode&id=$company_id]]></Url>
    </item>
  </Articles>
</xml>
";
        echo $text;exit();
    }
    function xml_to_array($xml){
        // 创建解析器
        $parser = xml_parser_create();
        // 将 XML 数据解析到数组中
        xml_parse_into_struct($parser, $xml, $vals, $index);
        // 释放解析器
        xml_parser_free($parser);
        // 数组处理
        $arr = array();
        $t=0;
        foreach($vals as $value) {
            $type = $value['type'];
            $tag = $value['tag'];
            $level = $value['level'];
            $attributes = isset($value['attributes'])?$value['attributes']:"";
            $val = isset($value['value'])?$value['value']:"";
            switch ($type) {
                case 'open':
                    if ($attributes != "" || $val != "") {
                        $arr[$t]['tag'] = $tag;
                        $arr[$t]['attributes'] = $attributes;
                        $arr[$t]['level'] = $level;
                        $t++;
                    }
                    break;
                case "complete":
                    if ($attributes != "" || $val != "") {
                        $arr[$t]['tag'] = $tag;
                        $arr[$t]['attributes'] = $attributes;
                        $arr[$t]['val'] = $val;
                        $arr[$t]['level'] = $level;
                        $t++;
                    }
                    break;
            }
        }
        return $arr;
    }

发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~