ThinkPHP 每天只能提现一下业务代码

  //限制每天只可提现一次
        $tdy=db('fenhong')->where(array('user_id'=>$user))->whereTime('addtime', 'today')->find();
        if($tdy){
            $res = ['status'=>'0','message'=>'每天只能提现一次'];
            return json($res);exit;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的ThinkPHP 5.1版本的微信提现代码示例: ```php <?php namespace app\index\controller; use think\Controller; use think\facade\Config; use think\facade\Log; use think\facade\Request; class Withdraw extends Controller { // 微信提现接口 public function wechatWithdraw() { // 获取请求参数 $params = Request::param(); // 获取微信支付配置信息 $wxPayConfig = Config::get('wxpay'); // 请求参数构造 $data = [ 'mch_appid' => $wxPayConfig['appid'], 'mchid' => $wxPayConfig['mchid'], 'nonce_str' => md5(uniqid()), 'partner_trade_no' => $params['order_no'], 'openid' => $params['openid'], 'check_name' => 'NO_CHECK', // 不校验真实姓名 'amount' => $params['amount'], // 提现金额,单位分 'desc' => '提现描述', 'spbill_create_ip' => $_SERVER['REMOTE_ADDR'], ]; // 生成签名 $data['sign'] = $this->makeSign($data, $wxPayConfig['key']); // 数组转xml格式 $xmlData = $this->arrayToXml($data); // 发送请求 $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; $response = $this->postXmlCurl($xmlData, $url, true, 6, $wxPayConfig['sslcert_path'], $wxPayConfig['sslkey_path']); // 解析返回的xml数据 $result = $this->xmlToArray($response); // 返回结果 if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { // 提现成功 return json(['code' => 0, 'msg' => '提现成功']); } else { // 提现失败 Log::error('微信提现失败:' . $response); return json(['code' => 1, 'msg' => '提现失败,请重试']); } } // 生成签名 private function makeSign($data, $key) { // 去除数组中的空值 $data = array_filter($data); // 按照键名的字典序排序 ksort($data); // 生成字符串 $stringA = ''; foreach ($data as $key => $value) { $stringA .= $key . '=' . $value . '&'; } $stringA .= 'key=' . $key; // 进行MD5签名并转化为大写 return strtoupper(md5($stringA)); } // 数组转xml格式 private function arrayToXml($data) { $xml = "<xml>"; foreach ($data as $key => $value) { if (is_numeric($value)) { $xml .= "<" . $key . ">" . $value . "</" . $key . ">"; } else { $xml .= "<" . $key . "><![CDATA[" . $value . "]]></" . $key . ">"; } } $xml .= "</xml>"; return $xml; } // 发送post请求xml数据 private function postXmlCurl($xmlData, $url, $useCert = false, $timeout = 30, $sslcert_path = '', $sslkey_path = '') { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData); if ($useCert == true) { curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); curl_setopt($ch, CURLOPT_SSLCERT, $sslcert_path); curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); curl_setopt($ch, CURLOPT_SSLKEY, $sslkey_path); } $data = curl_exec($ch); curl_close($ch); return $data; } // xml转数组 private function xmlToArray($xml) { // 禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlString = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $result = json_decode(json_encode($xmlString), true); return $result; } } ``` 其中,$wxPayConfig是微信支付的配置信息,可以在config目录下的wxpay.php文件中进行配置。 该示例仅供参考,实际使用时需要根据自己的业务需求进行相应的修改和完善。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桃花岛主70

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值