Micro-trust public platform developer Postxml Assistant [PHP version]

Source: Internet
Author: User

It is estimated that online search has micro-credit development and does not return information. A variety of problems arise, but the server-side simulation, no test, today I wrote a class that specializes in testing the problems encountered in the development of micro-trust, this class is simple, and can simulate the submission, return to the simulation of the micro-trust servers return information! This development is very simple and clear! What you need can be taken away!

<?php/* @author Widuu * @time 2013-7-4 *@ analog submission test micro-data * * Class winxinpost{private $event = "";
    Private $content = "";
    
    Private $time; * * Use the strict adherence to the micro-trust platform Parameters configuration Http://mp.weixin.qq.com/wiki/index.php?title= Message Interface Guide * If it is text or image type directly input $content * other Enter an array for example, location input *<location_x>23.134521</location_x> *&LT;LOCATION_Y&GT;113.358803&LT;/LOCATION_Y&G
     T * <Scale>20</Scale> * <label><!
     [cdata[Position Information]]></label> * Array (' 1.29290 ', ' 12.0998 ', ' 20 ', ' position information ');
        * */Public function __construct ($event, $url, $content) {$this-> event = $event;
        $this-> url = $url;
        $this-> content = $content;
    $this-> time = time (); //Returns the received message public function result () {$POSTOBJ = simplexml_load_string ($this->post (), ' Simplexmlelemen
        T ', libxml_nocdata); foreach (array) $postObj as $key => $value) {$str. = $key. ' => '.$value. "
        <br> ";

    return $str; ///processed into XML data private function Xml_data () {$str = "<xml> <touserna Me>100012</tousername> <FromUserName>100012</FromUserName> <crea
                 tetime>{$this->time}</createtime> <msgtype>{$this->event}</msgtype>
         {$this->judgment ()} <MsgId>1234567890123456</MsgId> </xml>
         ";
    return $str; ///Simulate post submit private Function post () {$header [] = "content-type:text/xml";//define Content-type as XML $ ch = curl_init (); Initialize Curl curl_setopt ($ch, Curlopt_url, $this->url);//Set link curl_setopt ($ch, Curlopt_returntransfer, 1); Sets whether to return information curl_setopt ($ch, Curlopt_httpheader, $header);//Set HTTP header curl_setopt ($ch, Curlopt_post, 1);//Set to Post mode curl_setopt ($ch, curlopt_postfields, $this->xml_data ());//post Data $response = curl_exec ($ch);//Receive return information if (Curl_errno ($ch)) {//error is apparent
        Error message Print curl_error ($ch); } curl_close ($ch);
     Close the Curl link return $response;
    }//Text message Private function text () {return "<content>{$this->content}</content>";
    }//Graphics message Private function image () {return "<picurl>{$this->content}</picurl>";
        }//Link message private Function link () {$data = $this->content;
            $str = "<title>{$data [0]}</title> <description>{$data [1]}</description>
        <url>{$data [2]}</url> ";
    return $str;
        }//Location message Private function location () {$data = $this->content; $str = "<location_x>{$data [0]}</location_x> <location_y>{$data [1]}</location _y>;
         scale>20</scale> <label>{$data [3]}</label> ";
    return $str;
        ///load the corresponding item based on the message type Private function judgment () {$type = $this->event;
    return $this-> $type ();
} $a = new Winxinpost ("text", "http://www.php100.com/wx_sample.php", 11111); echo $a->result ();

I just downloaded the SDK from the website to do the test wx_sample.php not change the premise is that you want to see wx_sample.php this thing is not 500 wrong ha, screenshot as follows



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.