PHP micro-Credit development of the custom menu implementation _php Skills

Source: Internet
Author: User
Tags curl php framework

There is a conflict between edit mode and development mode. So after we enable the development of the micro-credit public number, those menus are not visible, OH. But now the personal subscription number is not to use advanced developer mode, such as custom menus, but we can still test the test number, and then move the code to the service number.

Custom types include the following:

1, click: Click to push Events
• The user clicks the Click Type button, the micro-trust server will push the message type to the developer (Reference Message Interface Guide) through the message interface, and bring the key value that the developer fills in the button, the developer can interact with the user through the custom key value;

2, view: Jump URL
• The user clicks the View Type button, the micro-letter client will open the developer in the button fills in the webpage URL, may obtain the user basic information interface with the webpage authorization to obtain the user basic information.

3, Scancode_push: Sweep code Push event
• The user clicks the button, the micro-letter client will adjust sweep a sweep tool, completes after the scanning code operation displays the scan result (if is the URL, will enter the URL), and will sweep the code the result to the developer, the developer may send the message.

4, scancode_waitmsg: sweep code push event and pop-up "message received" Prompt box
• The user clicks the button, the micro-letter client will adjust sweep a sweep tool, completes the sweep code operation, will sweep the code the result to the developer, at the same time collect sweeps a sweep tool, then pops up "the message receives in" The Prompt box, then may receive the message which the developer sends.

Custom types include the following:

5, Pic_sysphoto: pop-up system photo map users click the button, micro-letter client will be tuned system camera, complete the photo operation, will be taken photos
Send it to the developer, push the event to the developer, and close the system camera, and then you may receive a message from the developer.

6, Pic_photo_or_album: pop-up photo or album Hair map users click the button, the micro-letter client will pop-up selector for users to choose "Photo" or "from the phone album selection." The user chooses to go through the other two processes.

7, Pic_weixin: pop-up micro-letter photo album, the user clicks the button, micro-letter clients will be transferred to the micro-letter album, the completion of the selection operation, will select the photo hair
To the developer's server, and push the event to the developer, and then put up the album, and then may receive a message from the developer.

Provide code, as long as the upload code to the server, pay attention to the public number can see the custom menu in development mode

$appid = ' The AppID of the micro-faith public number '; 
$appsecret = ' The Appsecret of the micro-faith public number '; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret=$ 
Appsecret "; 
$output = Https_request ($url); 
$jsoninfo = Json_decode ($output, true); 
$access _token = $jsoninfo ["Access_token"]; 
     $jsonmenu = ' {button ': [{' name ': ' School system ', ' Sub_button ': [{' Type ': ' Click ', ' name ': ' Schedule ', "Key": "Schedule"}, {"Type": "click", "Name": "Personal Information", "Key": "Personal Information"}, {"Type": "Click", "Name": "Peacetime results", "key": "Peacetime Results"}, {"Type": "click", "Name": "Rewards and punishments record", "Key": "Rewards and punishments 
     Record '}]}, {' name ': ' Technology sharing ', ' Sub_button ': [{' Type ': ' Click ', ' Name ': ' Mobile Web development ', "Key": "Mobile Web Development"}, {"Type": "click", "Name": "Java EE framework", "Key": "Java EE framework"}, {" Type ': ' Click ', ' Name ': ' Android development ', ' key ': ' Android Development '}, {' type ': 'Click, "name": "PHP Framework", "Key": "PHP Framework"}]},{"name": "Technical Support", "Sub_button": [{] Type: "Click", "Name": "Online customer service", "key": "Online Customer Service"}, {"Type": "click", "Name": "Technology sharing", "Ke  
  Y ": Technology Sharing"}, {"Type": "View", "name": "Weather Forecast", "url": "Http://m.hao123.com/a/tianqi"}] 
 
 
 } 
 
 ] 
 }'; 
 Create Menu Implementation $url = ' https://api.weixin.qq.com/cgi-bin/menu/create?access_token= '. $access _token; 
 $result = Https_request ($url, $jsonmenu); 
 Var_dump ($result); 
  function Https_request ($url, $data = null) {$curl = Curl_init (); 
  curl_setopt ($curl, Curlopt_url, $url); 
  curl_setopt ($curl, curlopt_ssl_verifypeer,0); 
  curl_setopt ($curl, curlopt_ssl_verifyhost,0); 
   if (!empty ($data)) {curl_setopt ($curl, curlopt_post,1); 
  curl_setopt ($curl, Curlopt_postfields, $data); 
  curl_setopt ($curl, curlopt_returntransfer,1); 
  $output = curl_exec ($curl); 
  Curl_close ($curl); 
 return $output;  }

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.