介绍
这篇文章给大家分享的是有关基于thinkphp5框架实现微信小程序支付/退款/订单查询/退款查询的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
微信小程序或微信支付相关操作支付退款订单查询退款查询支付成功,进行回调退款成功进行回调用到的方法
支付
/* * *预支付请求接口(POST) * @param字符串$ openid openid * @param字符串$身体商品简单描述 * @param字符串$ order_sn订单编的号 * @param字符串$ total_fee金额 * @return json的数据 */公共函数预付() { tp_log(& # 39;预支付请求数据===祝辞& # 39;。json_encode ($ _POST) & # 39;提前支付# 39;,请求()→控制器()); $ goods_user=db (& # 39; tf_goods_user& # 39;)→(数组(& # 39;order_no& # 39;=比;$ _POST [& # 39; order_no& # 39;]))→找到(); 美元商品=db (& # 39; tf_goods& # 39;)→(数组(& # 39;id # 39;=比;$ goods_user [& # 39; goods_id& # 39;]))→找到();//判断产品的数量 如果(($商品[& # 39;sales_initial& # 39;] -商品美元[& # 39;sales_actual& # 39;]) & lt;=0) { $返回[& # 39;状态# 39;]=0; $返回[& # 39;信息# 39;]=& # 39;此产品已售完& # 39;; 退出(json_encode()返回美元); } $ order_no=$ _POST [& # 39; order_no& # 39;];//订单号 $ is_sale=$ _POST [& # 39; is_sale& # 39;]; $ openid=$ _POST [& # 39; openid # 39;]; $ goods_name=$ _POST [& # 39; goods_name& # 39;]; $ pay_price=$ _POST[& # 39;价格# 39;]; $附加[& # 39;is_sale& # 39;]=$ _POST [& # 39; is_sale& # 39;]; $附加[& # 39;sale_id& # 39;]=$ _POST [& # 39; sale_id& # 39;]; nonce_str=这→美元nonce_str();//随机字符串 order_no_ssh=这→美元get_orderssh ();//商户订单号//组装支付数据 $ data=https://www.yisu.com/zixun/[ “appid”=>配置(“pay.APPID”), “mch_id”=>配置(“pay.MCHID”), “nonce_str”=> nonce_str美元, “身体”=> goods_name美元//商品名称组合 “附加”=> json_encode(附加美元), “out_trade_no”=> order_no_ssh美元,order_no美元//,//订单号商户订单号 “total_fee”=> intval中(pay_price * 100美元), “spbill_create_ip”=> $ _SERVER (“REMOTE_ADDR”), “notify_url”=>配置(“pay.NOTIFY_URL”), “trade_type”=>“JSAPI’, openid的openid美元=> ];//订单支付表创建订单支付数据 $ p_o_data [' createtime ')=(); $ p_o_data [' order_no ']=$ order_no; $ p_o_data [' order_no_ssh ']=$ order_no_ssh; $ p_o_data[‘准备好’]=json_encode(元数据); $ p_o_return=db (tf_pay_order) ->插入($ p_o_data); 如果(! $ p_o_return) {//失败 返回(“状态”)=1美元; 返回(“信息”)=p_o_data美元; 退出(json_encode()返回美元); }//获取签名 $符号=$ this -> makeSign(元数据); $ data[“标志”]=$符号; 美元$ xml=$ this -> toXml(数据); $ url=' https://api.mch.weixin.qq.com/pay/unifiedorder ';//发起支付接口链接//发起预支付请求 $ prepay_return_reslut_xml=$ this -> http_request ($ url, $ xml); $ xml_to_arr=$ this -> fromXml ($ prepay_return_reslut_xml); $ return_result=json_encode (xml_to_arr美元,真实); tp_log(“预支付请求返回数据数组===> '。return_result美元,“预付”,请求()->控制器());//记录预支付返回信息 db (“tf_goods_order”) ->(数组(“order_no”=> order_no美元)) ->更新(阵列( “go_pay”=> return_result美元, “updatetime”=>时间(), “updateuser”=> openid美元 )); 如果(xml_to_arr美元“return_code”==俺晒Α? & $ xml_to_arr [' result_code ']=='成功'){//成功 $=时间();//临时数组用于签名 $ tmp=( “appId”=>配置(“pay.APPID”), “nonceStr”=> nonce_str美元, “包”=>“prepay_id='。美元xml_to_arr (“prepay_id”), “signType”=>“MD5’, “时间戳”=>“$”, ]; $ data[“时间戳”]=" $时间”;//时间戳 $ data [' nonceStr ']=$ nonce_str;//随机字符串 $ data [' signType ')=癕D5”;//签名算法、暂支持MD5 $ data['包']=皃repay_id=' xml_to_arr美元。[' prepay_id '];//统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=* $ data [' paySign ']=$ this -> makeSign (tmp);//签名,具体签名方案参见微信公众号支付帮助文档;$ data [' out_trade_no ']=$ out_trade_no; 返回(“状态”)=1美元; 返回(“信息”)=美元数据; 其他}{//失败 返回(“状态”)=1美元; 返回(“信息”)=xml_to_arr美元; } 退出(json_encode()返回美元); }//旋度请求 公共函数http_request (url, data=零美元,美元头=array ()) { 旋度=美元curl_init (); 如果(count($头)>=1){ curl_setopt ($ curl CURLOPT_HTTPHEADER头美元); } curl_setopt ($ curl CURLOPT_URL $ url); curl_setopt ($ curl CURLOPT_SSL_VERIFYPEER假); curl_setopt ($ curl CURLOPT_SSL_VERIFYHOST假); 如果(!空(元数据)){ curl_setopt(美元curl CURLOPT_POST 1); curl_setopt ($ curl CURLOPT_POSTFIELDS $ data); } curl_setopt(美元curl CURLOPT_RETURNTRANSFER 1); (输出=curl_exec美元旋度); curl_close($旋度); 返回输出美元; }基于thinkphp5框架实现微信小程序支付/退款/订单查询/退款查询的方法