也希望大家多多支持脚本之家,微信支付、微信

作者:美狮美高梅官方网站

本文实例为大家分享了使用Thinkphp框架开发移动端接口代码,给原生APP提供api接口,具体内容如下

微信入口绑定,微信事件处理,微信API全部操作包含在这些文件中。微信支付、微信红包、微信卡券、微信小店。

mysql教程i 数据连接类
class Mydb extends mysqli
{
    protected $_databasehost = 'localhost';
    protected $_databaseuser = 'root';
    protected $_databasepass = '123456';
    protected $_databasename = 'test';
    protected $_databaseport = '3306';
 protected $_fetch_method = MYSQLI_ASSOC;
 protected $_databasechar = 'utf8';
   
 /**
  * Enter description here...
  *
  * @param string $host
  * @param string $user
  * @param string $pass
  * @param string $name
  * @param int $port
  * @param string $char
  */
    function __construct($host='',$user='',$pass='',$name='',$port='',$char='')
    {   
        $this->_databasehost = empty($host) ? $this->_databasehost : $host;
        $this->_databaseuser = empty($user) ? $this->_databaseuser : $user;
        $this->_databasepass = empty($pass) ? $this->_databasepass : $pass;
        $this->_databasename = empty($name) ? $this->_databasename : $name;
        $this->_databaseport = empty($port) ? $this->_databaseport : $port;
  $this->_databasechar = empty($char) ? $this->_databasechar : $char;
        try{
            parent::__construct($this->_databasehost,$this->_databaseuser,
                $this->_databasepass,$this->_databasename,
                $this->_databaseport);
            if(mysqli_connect_errno()){
                die("服务器连接失败");
            }
            if(!parent::set_charset($this->_databasechar)){
                die("数据库教程无法使用utf-8编码");
            }           
        }catch(Exception $e){
            die($e->getMessage());
        }   
    }    

  1. 使用TP框架时 放在common文件夹下文件名就叫function.php

    'Success', 'msg' => $msg, 'data' =>$data ); print json_encode;} / @param null $msg 返回具体错误的提示信息 @param flag success CURD 操作失败 Function descript:返回标志信息 ‘Error',和提示信息的json 数组 /function returnApiError{ $result = array( 'flag' => 'Error', 'msg' => $msg, ); print json_encode;} / @param null $msg 返回具体错误的提示信息 @param flag success CURD 操作失败 Function descript:返回标志信息 ‘Error',和提示信息,当前系统繁忙,请稍后重试; /function returnApiErrorExample(){ $result = array( 'flag' => 'Error', 'msg' => '当前系统繁忙,请稍后重试!', ); print json_encode;} / @param null $data @return array|mixed|null Function descript: 过滤post提交的参数; */ function checkDataPost{ if{ $data = explode; foreach{ if||{ if($_POST[$k]!==0 && $_POST[$k]!=='0'){ returnApiError; } } } unset; $data = I; unset($data['URL'],$data['token']); return $data; }} / @param null $data @return array|mixed|null Function descript: 过滤get提交的参数; */function checkDataGet{ if{ $data = explode; foreach{ if||{ if($_GET[$k]!==0 && $_GET[$k]!=='0'){ returnApiError; } } } unset; $data = I; unset($data['URL'],$data['token']); return $data; }}

  2. 查询单个果品详细信息

    /* 发布模块 获取信息单个果品详细信息 / public function getMyReleaseInfo(){ //检查是否通过post方法得到数据 checkdataPost; $where['id'] = $_POST['id']; $field[] = 'id,fruit_name,high_price,low_price,address,size,weight,fruit_pic,remark'; $releaseInfo = $this->release_obj->findRelease; $releaseInfo['remark'] = mb_substr($releaseInfo['remark'],0,49,'utf-8').'...'; //多张图地址按逗号截取字符串,截取后如果存在空数组则需要过滤掉 $releaseInfo['fruit_pic'] = array_filter(explode(',', $releaseInfo['fruit_pic'])); $fruit_pic = $releaseInfo['fruit_pic'];unset($releaseInfo['fruit_pic']); //为图片添加存储路径 foreach($fruit_pic as $k=>$v ){ $releaseInfo['fruit_pic'][] = '; } if{ returnApiSuccess; }else{ returnApiError; } }

  3. findRelease() 方法的model

    /* 查询一条数据 */ public function findRelease{ if($where['status'] == '' || empty{ $where['status'] = array; } $result = $this->where->field; return $result; }

  4. app端接收到的数据

    { "flag": "success", "message": "", "responseList": { "id": "2", "fruit_name": "苹果", "high_price": "8.0", "low_price": "5.0", "address": "天津小白楼水果市场", "size": "2.0", "weight": "2.0", "remark": "急需...", "fruit_pic": [ "", "" ] }}

  1. [代码]index.php

    wcValid();

  2. [代码]微信入口类

    token = $token; } public function wcCheckSignature(){ try{ if { throw new Exception('TOKEN is not defined!'); } $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = $this->token; $tmpArr = array($token, $timestamp, $nonce); // use SORT_STRING rule sort; $tmpStr = implode; $tmpStr = sha1; if( $tmpStr == $signature ){ return true; }else{ return false; } } catch { echo 'Message: ' .$e->getMessage(); } } public function wcValid(){ $echoStr = isset && !empty ? addslashes : NULL; if{ $this->wcMsg(); } else{ //valid signature , option if($this->wcCheckSignature{ echo $echoStr; exit; } else{ exit(); } } } public function wcMsg(){ //get post data, May be due to the different environments $postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) && !empty($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : ""; if{ libxml_disable_entity_loader; $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $this->zcLog; $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $MsgType = $postObj->MsgType; if{//执行事件相应 $Event = $postObj->Event; switch { case 'subscribe'://关注 break; case 'unsubscribe'://取消关注 break; case 'SCAN'://扫描 break; case 'LOCATION'://地址 break; case 'CLICK'://点击时间 break; case 'VIEW'://跳转 break; case 'card_pass_check'://卡券审核通过 break; case 'card_not_pass_check'://卡券审核失败 break; case 'user_get_card'://用户领取卡券 break; case 'user_del_card'://用户删除卡券 break; case 'user_view_card'://用户浏览会员卡 break; case 'user_consume_card'://用户核销卡券 break; case 'merchantorder'://微小店用户下单付款 break; default: break; } } else{ switch { case 'text'://文本格式 break; case 'image'://图片格式 break; case 'voice'://声音 break; case 'video'://视频 break; case 'shortvideo'://小视频 break; case 'location'://上传地理位置 break; case 'link'://链接相应 break; default: break; } } //////////////////////////////////////////////////////////////////// $keyword = trim; $time = time(); $textTpl = " %s 0 "; if{ $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; } else{ echo "Input something..."; } //////////////////////////////////////////////////////////////////// } else{ echo "暂时没有任何信息!"; exit; } } //日志LOG public function zcLog{ $this->returnAy = array(); $this->returnAy['errcode'] = $errcode; $this->returnAy['errmsg'] = $errmsg; $this->returnAy['errtime'] = date; $logfile = fopen("logfile".date.".txt", "a+"); $txt = json_encode."n"; fwrite; fclose; //return $this->returnAy; } }

  3. [代码]微信操作类 - 更新了自定义菜单部分

    • @link @version 2.0.1 @uses $wxApi = new WxApi(); @package 微信API接口 陆续会继续进行更新 **/ class WxApi { //const appId = ""; //const appSecret = ""; const appId = ""; const appSecret = ""; //const mchid = ""; //商户号 //const privatekey = ""; //私钥 public $parameters = array(); public function __construct(){ } /** 微信提交API方法,返回微信指定JSON **/ public function wxHttpsRequest{ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec; curl_close; return $output; } /** 微信带证书提交数据 - 微信红包使用 **/ public function wxHttpsRequestPem($url, $vars, $second=30,$aHeader=array; //超时时间 curl_setopt($ch,CURLOPT_TIMEOUT,$second); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); //这里设置代理,如果有的话 //curl_setopt($ch,CURLOPT_PROXY, '10.206.30.98'); //curl_setopt($ch,CURLOPT_PROXYPORT, 8080); curl_setopt; curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); //以下两种方式需选择一种 //第一种方法,cert 与 key 分别属于两个.pem文件 //默认格式为PEM,可以注释 curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM'); curl_setopt($ch,CURLOPT_SSLCERT,getcwd().'/apiclient_cert.pem'); //默认格式为PEM,可以注释 curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM'); curl_setopt($ch,CURLOPT_SSLKEY,getcwd().'/apiclient_key.pem'); curl_setopt($ch,CURLOPT_CAINFO,'PEM'); curl_setopt($ch,CURLOPT_CAINFO,getcwd; //第二种方式,两个文件合成一个.pem文件 //curl_setopt($ch,CURLOPT_SSLCERT,getcwd; if >= 1 ){ curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); } curl_setopt; curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); $data = curl_exec{ curl_close; return $data; } else { $error = curl_errno; echo "call faild, errorCode:$errorn"; curl_close; return false; } } /** 微信获取AccessToken 返回指定微信公众号的at信息 **/ public function wxAccessToken($appId = NULL , $appSecret = NULL){ $appId = is_null ? self::appId : $appId; $appSecret = is_null ? self::appSecret : $appSecret; $data = json_decode(file_get_contents; if ($data->expire_time < time { //echo $appId,$appSecret; $url = "; $result = $this->wxHttpsRequest; //print_r; $jsoninfo = json_decode; $access_token = $jsoninfo["access_token"]; if { $data->expire_time = time() + 7000; $data->access_token = $access_token; $fp = fopen("access_token.json", "w"); fwrite($fp, json_encode; } } else { $access_token = $data->access_token; } return $access_token; } /** 微信获取AccessToken 返回指定微信公众号的at信息 **/ public function wxJsApiTicket($appId = NULL , $appSecret = NULL){ $appId = is_null ? self::appId : $appId; $appSecret = is_null ? self::appSecret : $appSecret; $data = json_decode(file_get_contents; if ($data->expire_time < time { $url = "); $result = $this->wxHttpsRequest; $jsoninfo = json_decode; $ticket = $jsoninfo['ticket']; if { $data->expire_time = time() + 7000; $data->jsapi_ticket = $ticket; $fp = fopen("jsapi_ticket.json", "w"); fwrite($fp, json_encode; } } else { $ticket = $data->jsapi_ticket; } return $ticket; } /** 微信通过OPENID获取用户信息,返回数组 **/ public function wxGetUser{ $wxAccessToken = $this->wxAccessToken(); $url = ""; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /** 微信生成二维码ticket **/ public function wxQrCodeTicket{ $wxAccessToken = $this->wxAccessToken(); $url = "; $result = $this->wxHttpsRequest; return $result; } /** 微信通过ticket生成二维码 **/ public function wxQrCode{ $url = "" . urlencode; return $url; } /** 发送自定义的模板消息 **/ public function wxSetSend($touser, $template_id, $url, $data, $topcolor = '#7B68EE'){ $template = array( 'touser' => $touser, 'template_id' => $template_id, 'url' => $url, 'topcolor' => $topcolor, 'data' => $data ); $jsonData = json_encode; $result = $this->wxSendTemplate; return $result; } /** 微信设置OAUTH跳转URL,返回字符串信息 - SCOPE = snsapi_base //验证时不返回确认页面,只能获取OPENID **/ public function wxOauthBase($redirectUrl,$state = "",$appId = NULL){ $appId = is_null ? self::appId : $appId; $url = ""; return $url; } /** 微信设置OAUTH跳转URL,返回字符串信息 - SCOPE = snsapi_userinfo //获取用户完整信息 **/ public function wxOauthUserinfo($redirectUrl,$state = "",$appId = NULL){ $appId = is_null ? self::appId : $appId; $url = ""; return $url; } /** 微信OAUTH跳转指定URL **/ public function wxHeader{ header; } /** 微信通过OAUTH返回页面中获取AT信息 **/ public function wxOauthAccessToken($code,$appId = NULL , $appSecret = NULL){ $appId = is_null ? self::appId : $appId; $appSecret = is_null ? self::appSecret : $appSecret; $url = ""; $result = $this->wxHttpsRequest; //print_r; $jsoninfo = json_decode; //$access_token = $jsoninfo["access_token"]; return $jsoninfo; } /** 微信通过OAUTH的Access_Token的信息获取当前用户信息 // 只执行在snsapi_userinfo模式运行 **/ public function wxOauthUser{ $url = ""; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /** 创建自定义菜单 **/ public function wxMenuCreate{ $wxAccessToken = $this->wxAccessToken(); $url = "" . $wxAccessToken; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /** 获取自定义菜单 **/ public function wxMenuGet(){ $wxAccessToken = $this->wxAccessToken(); $url = "" . $wxAccessToken; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /** 删除自定义菜单 **/ public function wxMenuDelete(){ $wxAccessToken = $this->wxAccessToken(); $url = "" . $wxAccessToken; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /** 获取第三方自定义菜单 **/ public function wxMenuGetInfo(){ $wxAccessToken = $this->wxAccessToken(); $url = "" . $wxAccessToken; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /* 生成随机字符串 - 最长为32位字符串 **/ public function wxNonceStr($length = 16, $type = FALSE) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str = ""; for ($i = 0; $i < $length; $i++) { $str .= substr($chars, mt_rand - 1), 1); } if{ return strtoupper; } else { return $str; } } /*** 微信商户订单号 - 最长28位字符串 **/ public function wxMchBillno { if{ if(self::mchid == "" || is_null{ $mchid = time(); } else{ $mchid = self::mchid; } } else{ $mchid = substr,0,10); } return date.$mchid; } /*** 微信格式化数组变成参数格式 - 支持url加密 **/ public function wxSetParam{ if && !empty{ $this->parameters = $parameters; return $this->parameters; } else{ return array(); } } /*** 微信格式化数组变成参数格式 - 支持url加密 **/ public function wxFormatArray($parameters = NULL, $urlencode = FALSE){ if{ $parameters = $this->parameters; } $restr = "";//初始化空 ksort;//排序参数 foreach ($parameters as $k => $v){//循环定制参数 if (null != $v && "null" != $v && "sign" != $k) { if{//如果参数需要增加URL加密就增加,不需要则不需要 $v = urlencode; } $restr .= $k . "=" . $v . "&";//返回完整字符串 } } if {//如果存在数据则将最后“&”删除 $restr = substr($restr, 0, strlen; } return $restr;//返回字符串 } /*** 微信MD5签名生成器 - 需要将参数数组转化成为字符串[wxFormatArray方法] **/ public function wxMd5Sign($content, $privatekey){ try { if { throw new Exception; } if { throw new Exception; } $signStr = $content . "&key=" . $privatekey; return strtoupper; } catch { die; } } /*** 微信Sha1签名生成器 - 需要将参数数组转化成为字符串[wxFormatArray方法] **/ public function wxSha1Sign{ try { if { throw new Exception; } //$signStr = $content; return sha1; } catch { die; } } /*** 微信jsApi整合方法 - 通过调用此方法获得jsapi数据 **/ public function wxJsapiPackage(){ $jsapi_ticket = $this->wxJsApiTicket(); // 注意 URL 一定要动态获取,不能 hardcode. $protocol = (!empty && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = $protocol.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; $timestamp = time(); $nonceStr = $this->wxNonceStr(); $signPackage = array( "jsapi_ticket" => $jsapi_ticket, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url ); // 这里参数的顺序要按照 key 值 ASCII 码升序排序 $rawString = "jsapi_ticket=$jsapi_ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; //$rawString = $this->wxFormatArray; $signature = $this->wxSha1Sign; $signPackage['signature'] = $signature; $signPackage['rawString'] = $rawString; $signPackage['appId'] = self::appId; return $signPackage; } /*** 将数组解析XML - 微信红包接口 **/ public function wxArrayToXml{ if{ $parameters = $this->parameters; } if(!is_array || empty{ die; } $xml = ""; foreach { if { $xml.="".$val."".$key.">"; } else $xml.="".$key.">"; } $xml.=""; return $xml; } /*** 微信卡券:上传LOGO - 需要改写动态功能 **/ public function wxCardUpdateImg() { $wxAccessToken = $this->wxAccessToken(); //$data['access_token'] = $wxAccessToken; $data['buffer'] = '@D:workspacehtdocsyky_testlogo.jpg'; $url = "; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; //array { ["url"]=> string "" } } /*** 微信卡券:获取颜色 **/ public function wxCardColor(){ $wxAccessToken = $this->wxAccessToken(); $url = "; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /*** 微信卡券:创建卡券 **/ public function wxCardCreated { $wxAccessToken = $this->wxAccessToken(); $url = "" . $wxAccessToken; $result = $this->wxHttpsRequest; $jsoninfo = json_decode; return $jsoninfo; } /*** 微信卡券:JSAPI 卡券Package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改 **/ public function wxCardPackage{ $timestamp = time(); $api_ticket = $this->wxJsApiTicket(); $cardId = $cardId; $arrays = array($api_ticket,$timestamp,$cardId); sort; $string = sha1; $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

    wxOauthAccessToken; //print_r; // $openId = $Info['openid']; //} //////////////////////////////////////////// $signPackage = $wx->wxJsapiPackage(); //print_r; $kqInfo = $wx->wxCardPackage; $listInfo = $wx->wxCardListPackage();?> JSAPI接口测试

 function selectDb($name)
 {
   $this->_databasename = empty($name) ? $this->_databasename : $name;
   return $this->select_db($this->_databasename);
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

     wx.config({ debug: false, appId: '&lt;&amp;#63;php echo $signPackage["appId"];&amp;#63;&gt;', timestamp: &lt;&amp;#63;php echo $signPackage["timestamp"];&amp;#63;&gt;, nonceStr: '&lt;&amp;#63;php echo $signPackage["nonceStr"];&amp;#63;&gt;', signature: '&lt;&amp;#63;php echo $signPackage["signature"];&amp;#63;&gt;', jsApiList: [ // &#25152;&#26377;&#35201;&#35843;&#29992;&#30340; API &#37117;&#35201;&#21152;&#21040;&#36825;&#20010;&#21015;&#34920;&#20013; 'onMenuShareTimeline', 'onMenuShareAppMessage', 'addCard', 'openCard' ] }); wx.ready { // &#22312;&#36825;&#37324;&#35843;&#29992; API wx.onMenuShareAppMessage({ title: '&#20114;&#32852;&#32593;&#20043;&#23376;', desc: '&#22312;&#38271;&#22823;&#30340;&#36807;&#31243;&#20013;&#65292;&#25105;&#25165;&#24930;&#24930;&#21457;&#29616;&#65292;&#25105;&#36523;&#36793;&#30340;&#25152;&#26377;&#20107;&#65292;&#21035;&#20154;&#36319;&#25105;&#35828;&#30340;&#25152;&#26377;&#20107;&#65292;&#37027;&#20123;&#25152;&#35859;&#26412;&#26469;&#22914;&#27492;&#65292;&#27880;&#23450;&#22914;&#27492;&#30340;&#20107;&#65292;&#23427;&#20204;&#20854;&#23454;&#27809;&#26377;&#38750;&#24471;&#22914;&#27492;&#65292;&#20107;&#24773;&#26159;&#21487;&#20197;&#25913;&#21464;&#30340;&#12290;&#26356;&#37325;&#35201;&#30340;&#26159;&#65292;&#26377;&#20123;&#20107;&#26082;&#28982;&#38169;&#20102;&#65292;&#37027;&#23601;&#35813;&#20570;&#20986;&#25913;&#21464;&#12290;', link: 'http://movie.douban.com/subject/25785114/', imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg', trigger: function  { // &#19981;&#35201;&#23581;&#35797;&#22312;trigger&#20013;&#20351;&#29992;ajax&#24322;&#27493;&#35831;&#27714;&#20462;&#25913;&#26412;&#27425;&#20998;&#20139;&#30340;&#20869;&#23481;&#65292;&#22240;&#20026;&#23458;&#25143;&#31471;&#20998;&#20139;&#25805;&#20316;&#26159;&#19968;&#20010;&#21516;&#27493;&#25805;&#20316;&#65292;&#36825;&#26102;&#20505;&#20351;&#29992;ajax&#30340;&#22238;&#21253;&#20250;&#36824;&#27809;&#26377;&#36820;&#22238; alert; }, success: function ; }, cancel: function ; }, fail: function  { alert; } }); document.querySelector.onclick = function () { wx.onMenuShareTimeline({ title: '&#20114;&#32852;&#32593;&#20043;&#23376;', link: 'http://movie.douban.com/subject/25785114/', imgUrl: 'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg', trigger: function  { // &#19981;&#35201;&#23581;&#35797;&#22312;trigger&#20013;&#20351;&#29992;ajax&#24322;&#27493;&#35831;&#27714;&#20462;&#25913;&#26412;&#27425;&#20998;&#20139;&#30340;&#20869;&#23481;&#65292;&#22240;&#20026;&#23458;&#25143;&#31471;&#20998;&#20139;&#25805;&#20316;&#26159;&#19968;&#20010;&#21516;&#27493;&#25805;&#20316;&#65292;&#36825;&#26102;&#20505;&#20351;&#29992;ajax&#30340;&#22238;&#21253;&#20250;&#36824;&#27809;&#26377;&#36820;&#22238; alert; }, success: function ; }, cancel: function ; }, fail: function  { alert; } }); }; document.querySelector.onclick = function () { wx.addCard({ cardList: [ { cardId: 'p7G0Cj_1HGF2nijO4sTlVTzawFhI', cardExt: '{"timestamp":"&lt;&amp;#63;php echo $kqInfo['cardExt']['timestamp'];&amp;#63;&gt;", "signature":"&lt;&amp;#63;php echo $kqInfo['cardExt']['signature'];&amp;#63;&gt;"}' } ], success: function  { var cardList = res.cardList; // &#28155;&#21152;&#30340;&#21345;&#21048;&#21015;&#34920;&#20449;&#24687; alert; }, cancel: function ; }, fail: function  { alert; } }); }; var shareData = { title: '&#24494;&#20449;JS-SDK Demo', desc: '&#24494;&#20449;JS-SDK,&#24110;&#21161;&#31532;&#19977;&#26041;&#20026;&#29992;&#25143;&#25552;&#20379;&#26356;&#20248;&#36136;&#30340;&#31227;&#21160;web&#26381;&#21153;', link: 'http://demo.open.weixin.qq.com/jssdk/', imgUrl: 'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0' }; wx.onMenuShareAppMessage; wx.onMenuShareTimeline; var readyFunc = function onBridgeReady() { // &#32465;&#23450;&#20851;&#27880;&#20107;&#20214; document.querySelector.addEventListener { WeixinJSBridge.invoke('chooseCard', { "app_id": "&lt;&amp;#63;php echo $listInfo['app_id']&amp;#63;&gt;", "location_id ": '', "sign_type": "SHA1", "card_sign": "&lt;&amp;#63;php echo $listInfo['card_sign']&amp;#63;&gt;", "card_id": "&lt;&amp;#63;php echo $listInfo['card_id']&amp;#63;&gt;", "card_type": "&lt;&amp;#63;php echo $listInfo['card_type']&amp;#63;&gt;", "time_stamp": "&lt;&amp;#63;php echo $listInfo['time_stamp']&amp;#63;&gt;", "nonce_str": "&lt;&amp;#63;php echo $listInfo['nonce_str']&amp;#63;&gt;" }, function { alert(res.err_msg + res.choose_card_info); $.append(res.err_msg + res.choose_card_info); }); }); } if (typeof WeixinJSBridge === "undefined") { document.addEventListener('WeixinJSBridgeReady', readyFunc, false); } else { readyFunc(); }  

    /**
     * Enter description here...
     *
     */
 function __desstruct()
 {
  $this->close();
 }

  1. [代码]创建卡券

    $kqinfo = 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 = json_encode;$kqinfo = C::enJson; //print_r;//$resultData = $wx->wxCardCreated;

 /**
  * 设置返回值类型
  *
  * @param int $type
  */
 function setFetchMethod($type=2)
 {
  switch($type)
  {
   case '1':
    $this->_fetch_method = MYSQLI_NUM;
    break;
   case '2':
    $this->_fetch_method = MYSQLI_ASSOC;
    break;
   case '3':
    $this->_fetch_method = MYSQLI_BOTH;
    break;
   default:
    $this->_fetch_method = MYSQLI_ASSOC;
    break;
  }
 }

以上所述就是本文的全部内容,希望大家能够喜欢。

 /**
  * 插入前转义
  *
  * @param string|array $str
  * @return string
  */
 function quoteInto($str)
 {
  if(is_array($str)){
   foreach ($str as $key=>$val){
    $str[$key] = $this->real_escape_string($val);
   }
  }else{
   $str = $this->real_escape_string($str);
  }
  return $str;
 }

本文由美狮美高梅官方网站发布,转载请注明来源

关键词: