php怎么对接小程序,zzzphp对接小程序

## zzzphp对接微信小程序,百度小程序等教程

**说在前面:你首先已经会做小程序了,并且熟悉zzzphp,需要对接微信小程序,阅读下面的内容才会有帮助的**

1.首先确定自己小程序的ajax方法,后面有代码示例可以参考。

2.想好自己需要调用那些内容,需要自己会一点php,后面有示例代码。

3.做好服务器配置,php配置,域名白名单等基础配置。

小程序的ajax方法,示例中的/utils/ajax.js

```

function _param(obj = {}) {

let _ = encodeURIComponent

return Object.keys(obj).map(k => `${_(k)}=${_(obj[k])}`).join('&')

}

function ajax({url, query, data, success, fail, complete}) {

url = 'https://xxxxxx.com/wxapi/?act='+ url + _param(query)

wx.request({

url: url,

data: data,

method: 'POST',

header: { "Content-Type": "application/x-www-form-urlencoded"},

success: success,

fail: fail,

complete: complete

})

}

module.exports = ajax

```

小程序使用方法,实例中的/pages/index/index/js

```

let ajax = require('../../utils/ajax')

```

首页调用网站中的推荐产品,支持下拉加载更多

```

ajax({

url: 'contentlist',

data: { 'type': 'product', 'ispic': '1', 'num': '10', 'page': ++this.data.page},

success: res => {

if (res.data.length < this.data.num) {

loadedEnd: true

}

var imgalist = this.data.imgalist;

for (var index in res.data) {

imgalist.push(app.globalData.weburl + res.data[index].c_pic)

}

this.setData({

list: this.data.list.concat(res.data),

imgalist: imgalist

})

},

complete: _ => {

wx.hideToast()

}

})

```

网站后台建立wxapi/index.php文件。

```

require '../inc/zzz_class.php';

$act=safe_word(getform('act','get'));

switch ($act) {

case'contentlist':contentlist();break;

}

function contentlist(){

$where=array('c_onoff'=>1);

$type=safe_key(getform('act','post'));if($type) arr_add($where,'c_type',$type);

$brand=safe_key(getform('brand','post'));if($brand) arr_add($where,'c_brand',toutf($brand)) ;

$sid=safe_key(getform('sid','post'));if($sid) arr_add($where,'c_sid',$sid);

$id=safe_key(getform('id','post'));if($id) arr_add($where,'cid',splits($id)) ;

$ispic=safe_key(getform('ispic','post'));if($ispic) arr_add($where,'ispic',$ispic);

$istop=safe_key(getform('istop','post'));if($istop) arr_add($where,'istop',$istop);

$order=safe_key(getform('order','post'));

$num=safe_key(getform('num','post','num',conf('pagesize')));

$page=safe_key(getform('page','post','num',1));

$col=safe_key(getform('col','post'));$col = empty($col) ? 'cid,c_title,c_pic,c_addtime,c_pagedesc,zprice' :$col ;

$asc=safe_key(getform('asc','post','','asc'));

$desc=$asc=='asc' ? 'desc' : 'asc';

$order=array('istop'=>$desc,'isgood'=>$desc,'c_order'=>$asc,'c_addtime'=>$desc,'cid'=>$desc);

$data=db_load('content',$where,$col,$num,$order,$page);

echo tojson(array('code'=>1,'msg'=>'成功','where'=>$where,'data'=>($data)));

}

```

## 示例附件

[zzzphp+微信小程序示例](http://115.29.55.18/zzzphp+wxapp.zip)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值