uniapp调用支付宝app支付崩溃问题
2020-05-15 本文已影响0人
打不死的小强1118
1.问题描述
我司前端使用uniapp的云打包,在某一次打包之后,线上环境当前端唤起支付时,app就直接闪退,崩溃。
2.php后端代码
import('Vendor.alipay.AopClient', '', '.php');
$bank = M('Banks')->where(['id' => self::BANK_ALI])->find();
$parameter = $this->formAppData($order);
$apply['app_id'] = $bank['app_id'];
$apply['method'] = 'alipay.trade.app.pay';
$apply['charset'] = 'utf-8';
$apply['sign_type'] = 'RSA2';
$apply['timestamp'] = date('Y-m-d H:i:s');
$apply['version'] = 1.0;
$apply['notify_url'] = get_ali_app_notify();
$apply['biz_content'] = $parameter;
$aop = new \AopClient();
$aop->rsaPrivateKey = trim(file_get_contents($bank['ali_rsa_private_key']));
$aop->alipayrsaPublicKey = trim(file_get_contents($bank['ali_rsa_public_key']));
$paramStr = $aop->getSignContent($apply);
$sign = $aop->alonersaSign($paramStr, $aop->rsaPrivateKey, 'RSA2'); //生成签名
$apply['sign'] = $sign;
$str = $aop->getSignContentUrlencode($apply); //最终请求参数
return $str;
-----------------------------------------------------------------------------------
public function formAppData($order){
$arr['subject'] = $this->getSubject();
$arr['out_trade_no'] = $order['order_id'];
$arr['total_amount'] = $order['all_money'];
$arr['product_code'] = 'QUICK_MSECURITY_PAY';
$arr['enable_pay_channels'] = "balance,moneyFund,debitCardExpress";
return json_encode($arr);
}
3.解决方案
$arr['out_trade_no'] = strval($order['order_id']);
看了支付宝文章发现改字段必须要string类型,至于我们之前一直可以支付可能是前段打包的sdk更新了,新的sdk严格了这个类型,否则直接报错
(php弱类型语言,大家都容易去忽略变量的类型)