个人案例
- 易建哈酒网
本案例中,销售的是酒类单品;通过后台设置,你可以售卖任何单品。
易建哈酒网扫码体验
- 小程序最简单的滑动删除代码
网上看过不少关于微信小程序滑动删除的例子,感觉有点复杂。于是写了个简单点的例子,希望对大家有所帮助。 片段代码下载:https://developers.weixin.qq.com/s/sNy7ZfmI7mvj 问题关键点: 1、wxml的list中,添加: bindtouchmove="btn_touch" data-addr_id="{{item.addr_id}}" 然后,根据addr_id的值, <view class="footer" wx:if="{{del_id!=item.addr_id}}"> ...... <view class="footer_long" wx:else> 2、在js中,(1)初始化设置: data: { del_id: 0, }, (2)函数: btn_touch:function(e){ var addr_id = e.currentTarget.dataset.addr_id; this.setData({ del_id: addr_id, }); }, //取消删除 btn_cancel:function(e){ this.setData({ del_id: 0, }) }, 效果,如图,手指滑动时,内容向左滑动。 [图片] [图片] 主要代码如下: 一、js代码: // pages/index/index.js const app = getApp() Page({ data: { del_id: 0, }, onLoad: function (options) { var list=[{addr_id: "8", address: "广东省广州市四川省新港中路397号", is_default: "0", receiver_name: "张三", telphone: "020-81167888" },{ addr_id: "7", address: "辽宁省大连市新港中路39号", is_default: "0", receiver_name: "张三", telphone: "020-81167888" },{ addr_id: "4", address: "辽宁省大连市东华门街道小小园11号楼1004-5023", is_default: "1", receiver_name: "徐连科", telphone: "13840888081" }]; this.setData({ list: list, }) }, //删除 btn_del:function(para){ wx.request({ url: '', data: { openid:wx.getStorageSync('openid'), addr_id: para.currentTarget.dataset.addr_id, }, success: function (response) { wx.showModal({ title: '删除成功', content: '删除地址成功', success: function (res) { if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.redirectTo({ url: '/pages/index/index', }) } }, }); } }) }, radioChange(e) { wx.request({ url: '', data: { openid:wx.getStorageSync('openid'), addr_id: e.detail.value, } }) }, btn_add:function(){ wx.redirectTo({ url: '/pages/address/add', }) }, chooseAddress() { wx.chooseAddress({ success: (res) => { wx.request({ url: '', data: { openid:wx.getStorageSync('openid'), receiver_name: res.userName, telphone: res.telNumber, postal_code: res.postalCode, province: res.provinceName, city: res.cityName, district: res.nationalCode, address: res.detailInfo, }, success: function(res){ wx.showModal({ title: '添加成功', content: '添加地址成功', success: function (res) { if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.redirectTo({ url: '/pages/index/index', }) } }, }); } }) }, fail: function(err) { console.log(err) } }) }, btn_touch:function(e){ var addr_id = e.currentTarget.dataset.addr_id; this.setData({ del_id: addr_id, }); }, btn_cancel:function(e){ this.setData({ del_id: 0, }) }, }) 二、WXML代码: <!--pages/index/index.wxml--> <view class="main_view"> <view class="contain" wx:for="{{list}}" wx:key="addr_id"> <view class="list" bindtouchmove="btn_touch" data-addr_id="{{item.addr_id}}"> <view class="footer" wx:if="{{del_id!=item.addr_id}}"> <view class="footLeft"> <view class="Header"> <view class="title {{item.is_default === '1' ? 'txt-default' : ''}}"> <text>{{item.receiver_name}}</text> <text>{{item.telphone}}</text> </view> <view class="v-address"> <text>{{item.address}}</text> </view> </view> </view> <view class="footRight"> <navigator url="" hover-class="noner"> <view style="text-align:right;">修改</view> </navigator> <view class="line"></view> <view style="text-align:right;" class="{{item.is_default === '1' ? 'txt-default' : ''}}" data-addr_id="{{item.addr_id}}">默认</view> </view> </view> <view class="footer_long" wx:else> <view class="footLeft"> <view class="Header"> <view class="title {{item.is_default === '1' ? 'txt-default' : ''}}"> <text>{{item.receiver_name}}</text> <text>{{item.telphone}}</text> </view> <view class="v-address"> <text>{{item.address}}</text> </view> </view> </view> <view class="footRight"> <navigator url="" hover-class="noner"> <view style="text-align:right;">修改</view> </navigator> <view class="line"></view> <view style="text-align:right;" class="{{item.is_default === '1' ? 'txt-default' : ''}}" data-addr_id="{{item.addr_id}}">默认</view> </view> <view class="foot-del"> <view style="text-align:right;color:red" bindtap="btn_cancel">取消</view> <view class="line"></view> <view style="text-align:right;color:red" bindtap="btn_delete" data-addr_id="{{item.addr_id}}">删除</view> </view> </view> </view> </view> <view class="foot_margin"></view> <!-- <navigator url="/pages/address/add" hover-class="noner"></navigator> --> <view class="v-add_address" style="bottom:20rpx"> <view class="v-left" bindtap="chooseAddress">导入微信地址</view> </view> </view> 三、wxss代码: /* pages/index/index.wxss */ .contain{ margin-top: 0rpx; width: 100%; } .list{ border-top:13rpx solid #f2f2f2; background: #fff; width: 100%; padding: 0rpx 30rpx; } .Header{ border-bottom: 1px solid #f2f2f2; line-height: 50rpx; padding-top: 20rpx; } .title{ font-size:14px; } .footer{ display: flex; line-height: 82rpx; color:#666666; width: 100%; } .footer_long{ display: flex; line-height: 82rpx; color:#666666; width: 125%; margin-left: -25%; } .footLeft{ flex:3; padding-left: 36rpx; } .footRight{ flex:1; text-align:right; margin-right:40rpx; margin-top: 25rpx; display: flex; flex-direction:row-reverse; } .foot-del{ flex:1; text-align:right; margin-right:40rpx; margin-top: 25rpx; display: flex; flex-direction:row; } .line{ height:30rpx; width:1px; margin:25rpx 10rpx 10rpx 10rpx; background: #888; } .nav{ width:100%; height:89rpx; display:flex; justify-content:center; line-height: 45rpx; padding-top: 20rpx; position: relative; border-top: solid 4rpx #f1f1f1; } .navCent{ width:354rpx; height: 45rpx; border-radius: 16rpx; background: #ff4200; border:1px solid #318cff; display: flex; } .navText{ font-size: 12px; text-align: center; color: #fff; flex:1; } .navClick{ width: 100%; border-radius: 16rpx; height: 100%; background: #fff; color: #318cff; } .foot{ width: 100%; padding:0rpx 56rpx; padding-bottom: 120rpx; bottom: 0rpx; position: fixed; } .foot .btn{ border-radius: 30rpx; height: 98rpx; line-height: 98rpx; text-align: center; background: #ff4200; font-size: 18px; color: #fff; width: 634rpx; } .foot_margin{ height: 140rpx; } .v_empty{ width: 100%; height: 100%; background-color: #fff; } .img{ width:100%; margin-top: 30%; } .v-address{ font-size: 24rpx; color: #666; } .txt-default{ color: #ff4200; } .v-add_address{ display: flex; flex-direction: row; width: 100%; padding:0rpx 56rpx; bottom: 0rpx; position: fixed; text-align: center; } .v-left{ background: #ff4200; width: 80%; padding: 20rpx; border-radius: 10rpx; color: #fff; line-height: 60rpx; height: 60rpx; } 完毕。希望能帮到你。 片段代码下载:https://developers.weixin.qq.com/s/sNy7ZfmI7mvj
2021-12-03 - 易建哈酒网
代码不方便贴出来。不过,如果希望解决单项技术,可以微我。微信号:13840888081 [图片]
2021-01-13 - 微信分账时,xml格式错误解决方法
前两天做微信分账功能,遇到了xml错误,看着代码,怎么看怎么正确,可是,就是报错。 最后,退而求其次,换个方法,问题解决了。 1、首先,生成xml格式字符串 关键代码: public function toXml($arr) { $xml = '<xml>'; $xml .= $this->array_to_xml($arr); $xml .= '</xml>'; return $xml; } //array转xml public function array_to_xml($arr) { $xml = ''; foreach ($arr as $key => $val) { if (is_array($val)) { $xml .= '<' . $key . '>' . $this->array_to_xml($val) . '</' . $key . '>'; } else { $xml .= '<' . $key . '>' . $val . '</' . $key . '>'; } } return $xml; } 2、将这段文字写入xml文件 3、读取这个xml文件。代码如下: //1.设置分账账号 $receivers = array(); foreach ($profitSharingAccounts as $profitSharingAccount) { $tmp = array( 'type'=>$profitSharingAccount['type'], 'account'=>$profitSharingAccount['account'], 'amount'=>intval($profitSharingAccount['amount']), 'description'=>$profitSharingAccount['description'], ); $receivers[] = $tmp; } $receivers = json_encode($receivers); $totalCount = count($profitSharingOrders); $successCount = 0; $failCount = 0; $now = time(); //2.生成签名 $postArr = array( 'appid'=>$this->wxConfig['app_id'], 'mch_id'=>$this->wxConfig['mch_id'], 'nonce_str'=>md5(time() . rand(1000, 9999)), 'transaction_id'=>$profitSharingOrders['transaction_id'], 'out_order_no'=>$profitSharingOrders['out_trade_no'], 'receivers'=>$receivers, ); $sign = $this->sign->getSign($postArr, 'HMAC-SHA256',$this->wxConfig['md5_key']); $postArr['sign'] = $sign; //3.发送请求 $url = 'https://api.mch.weixin.qq.com/secapi/pay/profitsharing'; $postXML = $this->toXml($postArr); //为了适应xml格式,先保存到文件,再取出,这样xml格式就能适应了。 $filename = dirname(__FILE__).'/xml/subledger.xml'; file_put_contents($filename, $postXML); $postXML = file_get_contents($filename); 最后,调用post方法 $helper = new Common_util_pub(); $ret = $helper->postXmlSSLCurl($postXML, $url); postXmlSSLCurl方法代码: /** * 作用:使用证书,以post方式提交xml到对应的接口url */ function postXmlSSLCurl($xml, $url, $second = 30) { $ch = curl_init (); //超时时间 curl_setopt ( $ch, CURLOPT_TIMEOUT, $second ); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); //设置header curl_setopt ( $ch, CURLOPT_HEADER, FALSE ); //要求结果为字符串且输出到屏幕上 curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE ); //设置证书 //使用证书:cert 与 key 分别属于两个.pem文件 curl_setopt ( $ch, CURLOPT_SSLCERT, dirname(__FILE__).'/cacert/apiclient_cert.pem' ); curl_setopt ( $ch, CURLOPT_SSLKEY, dirname(__FILE__).'/cacert/apiclient_key.pem' ); //证书密码 curl_setopt($ch, CURLOPT_SSLCERTPASSWD, WxPayConf_pub::KEY ); //post提交方式 curl_setopt ( $ch, CURLOPT_POST, true ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $xml ); //启用时会汇报所有的信息,存放在STDERR或指定的 CURLOPT_STDERR 中。 curl_setopt($ch, CURLOPT_VERBOSE, '1'); $data = curl_exec ( $ch ); //返回结果 if ($data) { curl_close ( $ch ); return $data; } else { $error = curl_errno ( $ch ); echo "curl出错,错误码:$error" . "<br>"; echo "<a href='http://curl.haxx.se/libcurl/c/libcurl-errors.html'>错误原因查询</a></br>"; curl_close ( $ch ); return false; } } 其它代码,网上很多,就不贴出来了。
2021-01-06