作者 何书鹏

测试代付

... ... @@ -13,6 +13,8 @@ use app\api\model\Third;
use app\api\model\UserAddress;
use app\api\model\UserCoupon;
use app\common\controller\Api;
use fast\Http;
use think\Config;
use think\Db;
use think\exception\PDOException;
use Yansongda\Pay\Pay;
... ... @@ -584,7 +586,7 @@ class Order extends Api
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiParams (name="openid", type="string", required=false, description="代付人openid")
* @ApiParams (name="code", type="string", required=false, description="代付人code")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
... ... @@ -593,7 +595,7 @@ class Order extends Api
public function pay()
{
$order_id = $this->request->post('id');
$openid = $this->request->post('openid');
$code = $this->request->post('code');
empty($order_id) && $this->error('缺少必需参数');
$model = new \app\api\model\Order();
... ... @@ -607,14 +609,30 @@ class Order extends Api
->find();
if (!$third) $this->error('下单人未注册');
// 获取代付人的openid
$openid = $third['openid'];
if(!empty($code)){
$wxapi = Http::get('https://api.weixin.qq.com/sns/jscode2session',[
'js_code' => $code,
'grant_type' => 'authorization_code',
'secret' => Config::get('site.secret'),
'appid' => Config::get('site.appid')
]);//请求openid
$wxapi = json_decode($wxapi,true);
if (isset($wxapi['errcode'])){
$this->error($wxapi['errmsg']);
}
$openid = $wxapi['openid'];
}
$params = [
'type' => 'wechat',
'orderid' => $order['order_no'],
'title' => '订单号-'.$order['order_no'],
'amount' => $order['pay_price'],
// 'amount' => 0.01,
// 'amount' => $order['pay_price'],
'amount' => 0.01,
'method' => 'miniapp',
'openid' => !empty($openid) ? $openid : $third['openid'],
'openid' => $openid,
'notifyurl' => $this->request->domain().'/api/notify/orderNotify/type/wechat',
'returnurl' => '',
];
... ...