争怎路由网:是一个主要分享无线路由器安装设置经验的网站,汇总WiFi常见问题的解决方法。

微信API接口

时间:2022-9-12作者:未知来源:争怎路由网人气:

empty($parameters)){ die("参数不为数组无法解析"); } $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)) { $xml.="<".$key.">".$val."</".$key.">"; } else $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } $xml.="</xml>"; return $xml; } /******************************************************* * 微信卡券:上传LOGO - 需要改写动态功能 *******************************************************/ public function wxCardUpdateImg() { $wxAccessToken = $this->wxAccessToken(); //$data['access_token'] = $wxAccessToken; $data['buffer'] = '@D:\\workspace\\htdocs\\yky_test\\logo.jpg'; $url = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=".$wxAccessToken; $result = $this->wxHttpsRequest($url,$data); $jsoninfo = json_decode($result, true); return $jsoninfo; //array(1) { ["url"]=> string(121) "http://mmbiz.qpic.cn/mmbiz/ibuYxPHqeXePNTW4ATKyias1Cf3zTKiars9PFPzF1k5icvXD7xW0kXUAxHDzkEPd9micCMCN0dcTJfW6Tnm93MiaAfRQ/0" } } /******************************************************* * 微信卡券:获取颜色 *******************************************************/ public function wxCardColor(){ $wxAccessToken = $this->wxAccessToken(); $url = "https://api.weixin.qq.com/card/getcolors?access_token=".$wxAccessToken; $result = $this->wxHttpsRequest($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:创建卡券 *******************************************************/ public function wxCardCreated($jsonData) { $wxAccessToken = $this->wxAccessToken(); $url = "https://api.weixin.qq.com/card/create?access_token=" . $wxAccessToken; $result = $this->wxHttpsRequest($url,$jsonData); $jsoninfo = json_decode($result, true); return $jsoninfo; } /******************************************************* * 微信卡券:JSAPI 卡券Package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改 *******************************************************/ public function wxCardPackage($cardId){ $timestamp = time(); $api_ticket = $this->wxJsApiTicket(); $cardId = $cardId; $arrays = array($api_ticket,$timestamp,$cardId); sort($arrays); $string = sha1(implode("",$arrays)); $resultArray['card_id'] = $cardId; $resultArray['card_ext'] = array(); $resultArray['card_ext']['openid'] = 'oOmn4s9MiwqHSNNvPn0dBtU23toA'; $resultArray['card_ext']['timestamp'] = $timestamp; $resultArray['card_ext']['signature'] = $string; return $resultArray; } }

4. [代码]微信JSAPI

<?php
  require_once 'lib.inc.php';
  $wx = new WxApi();
  //通过网页获取openid
  //if(!isset($_GET['code'])){
  //  header("location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WxApi::appId."&redirect_uri=http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."&response_type=code&scope=snsapi_base&state=1#wechat_redirect");
  //}
  //else{
  //  $CODE = $_GET['code'];
  //  $Info = $wx->wxOauthAccessToken($CODE);
    //print_r($Info);
  //  $openId = $Info['openid'];  
  //}
  ////////////////////////////////////////////
 
  $signPackage = $wx->wxJsapiPackage();
  //print_r($signPackage);
  $kqInfo = $wx->wxCardPackage("");
  $listInfo = $wx->wxCardListPackage();
?>
<html>
  <head>
    <title>JSAPI接口测试</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     
    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  </head>
  <body>
    <p>
      <input type="button" id="batchAddCard" name="batchAddCard" value="添加卡券" /><br />
      <input type="button" id="openCard" name="openCard" value="拉起卡券库" /><br />
      <input type="button" id="ShareTimeLine" name="ShareTimeLine" value="分享朋友圈" /><br />
      <p id="showInfo">
       
      </p>
    </p>
     
    <script>
      wx.config({
       debug: false,
       appId: '<?php echo $signPackage["appId"];?>',
       timestamp: <?php echo $signPackage["timestamp"];?>,
       nonceStr: '<?php echo $signPackage["nonceStr"];?>',
       signature: '<?php echo $signPackage["signature"];?>',
       jsApiList: [
        // 所有要调用的 API 都要加到这个列表中
        'onMenuShareTimeline',
         'onMenuShareAppMessage',
         'addCard',
         'openCard'
       ]
      });
       
      wx.ready(function () {
        // 在这里调用 API
        wx.onMenuShareAppMessage({
          title: '互联网之子',
          desc: '在长大的过程中,我才慢慢发现,我身边的所有事,别人跟我说的所有事,那些所谓本来如此,注定如此的事,它们其实没有非得如此,事情是可以改变的。更重要的是,有些事既然错了,那就该做出改变。',
          link: 'http://movie.douban.com/subject/25785114/',
          imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg',
          trigger: function (res) {
            // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
            alert('用户点击发送给朋友');
          },
          success: function (res) {
            alert('已分享');
          },
          cancel: function (res) {
            alert('已取消');
          },
          fail: function (res) {
            alert(JSON.stringify(res));
          }
        });
         
      document.querySelector('#ShareTimeLine').onclick = function () {
        wx.onMenuShareTimeline({
            title: '互联网之子',
            link: 'http://movie.douban.com/subject/25785114/',
            imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg',
            trigger: function (res) {
                // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
                alert('用户点击分享到朋友圈');
            },
            success: function (res) {
                alert('已分享');
            },
            cancel: function (res) {
                alert('已取消');
            },
            fail: function (res) {
                alert(JSON.stringify(res));
            }
        });
      };  
       
       document.querySelector('#batchAddCard').onclick = function () {
        wx.addCard({
         cardList: [
          {
           cardId: 'p7G0Cj_1HGF2nijO4sTlVTzawFhI',
           cardExt: '{"timestamp":"<?php echo $kqInfo['cardExt']['timestamp'];?>", "signature":"<?php echo $kqInfo['cardExt']['signature'];?>"}'
          }
         ],
         success: function (res) {
          var cardList = res.cardList; // 添加的卡券列表信息
          alert(cardList);
         },
        cancel: function (res) {
            alert('已取消');
        },
        fail: function (res) {
            alert(JSON.stringify(res));
        }
        });
       };
        
       var shareData = {
        title: '微信JS-SDK Demo',
        desc: '微信JS-SDK,帮助第三方为用户提供更优质的移动web服务',
        link: 'http://demo.open.weixin.qq.com/jssdk/',
        imgUrl: 'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0'
       };
        
       wx.onMenuShareAppMessage(shareData);
        
       wx.onMenuShareTimeline(shareData);
      });
 
      var readyFunc = function onBridgeReady() {
        // 绑定关注事件
        document.querySelector('#openCard').addEventListener('click',
          function(e) {
            WeixinJSBridge.invoke('chooseCard', {
              "app_id": "<?php echo $listInfo['app_id']?>",
              "location_id ": '',
              "sign_type": "SHA1",
              "card_sign": "<?php echo $listInfo['card_sign']?>",
              "card_id": "<?php echo $listInfo['card_id']?>",
              "card_type": "<?php echo $listInfo['card_type']?>",
              "time_stamp": "<?php echo $listInfo['time_stamp']?>",
              "nonce_str": "<?php echo $listInfo['nonce_str']?>"
            },
          function(res) {
            alert(res.err_msg + res.choose_card_info);
            $("#showInfo").empty().append(res.err_msg + res.choose_card_info);
          });
        });
      }
       
      if (typeof WeixinJSBridge === "undefined") {
        document.addEventListener('WeixinJSBridgeReady', readyFunc, false);
      } else {
        readyFunc();
      }
 
     </script>
  </body>
</html>

5. [代码]创建卡券

$kqinfo = array("card" => array());
$kqinfo['card']['card_type'] = 'GENERAL_COUPON';
$kqinfo['card']['general_coupon'] = array('base_info' => array(), 'default_detail' => array());
$kqinfo['card']['general_coupon']['base_info']['logo_url'] = 'URL';
$kqinfo['card']['general_coupon']['base_info']['code_type'] = 'CODE_TYPE_QRCODE';
$kqinfo['card']['general_coupon']['base_info']['brand_name'] = '';
$kqinfo['card']['general_coupon']['base_info']['title'] = '测试卡券';
$kqinfo['card']['general_coupon']['base_info']['color'] = 'Color030';
$kqinfo['card']['general_coupon']['base_info']['notice'] = '测试测试测试';
$kqinfo['card']['general_coupon']['base_info']['description'] = '这是一张优惠券';
$kqinfo['card']['general_coupon']['base_info']['date_info']['type'] = 1;
$kqinfo['card']['general_coupon']['base_info']['date_info']['begin_timestamp'] = time();
$kqinfo['card']['general_coupon']['base_info']['date_info']['end_timestamp'] = time() + 100 * 24 * 3600;
$kqinfo['card']['general_coupon']['base_info']['sku']['quantity'] = 100000;
$kqinfo['card']['general_coupon']['default_detail'] = '测试数据\n测试数据\n测试数据';
 
//var_dump($kqinfo);
//$kqinfo = json_encode($kqinfo);
$kqinfo = C::enJson($kqinfo);
 
//print_r( $kqinfo);
//$resultData = $wx->wxCardCreated($kqinfo);

相关推荐:

php Restful api 示例

以上就是微信API接口的详细内容,更多请关注php中文网其它相关文章!


微信提供公众平台、朋友圈、消息推送等功能,用户可以通过“摇一摇”、“搜索号码”、“附近的人”、扫二维码方式添加好友和关注公众平台,同时微信将内容分享给好友以及将用户看到的精彩内容分享到微信朋友圈。



关键词:微信API接口




Copyright © 2012-2018 争怎路由网(http://www.zhengzen.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版