app获取支付宝user_id 唯一
支付宝流程
tp获取支付宝用户user_id唯一
咱们开始
第一步 下载demo
请自行注册开发者账号。
- 进入支付宝开放平台,文档中心》APP支付》下载SDK&Demo,放到tp框架的Vendor中

4.配置文件 在tp框架中配置接入支付宝需要的配置的参数
'ALI_CONFIG' => array(
'gatewayUrl' => 'https://openapi.alipay.com/gateway.do',
'appId' => 'appIDappIDappIDappIDappIDappIDappID',
'rsaPrivateKey' => 'AfewqFEWfefedwfewfewfewfewfewfewfwefewfewfeefwef',
'alipayrsaPublicKey' => 'ewqdwqfwqdfwqfwqfwqfqwfwqfwqfwqfwqfwqferagrGERW',
)
- 控制器代码
$id 需要修改的用户的, code是用户需要接受到前端的授权码
public function getUserId($id,$code)
{
require_once root_path() .'/vendor/Alipay/aop/AopClient.php';
require_once root_path() .'/vendor/Alipay/aop/request/AlipaySystemOauthTokenRequest.php';
$aliConfig = Config('app.ALI_CONFIG');
$aop = new \AopClient ();
$aop->gatewayUrl = $aliConfig['gatewayUrl'];
$aop->appId = $aliConfig['appId'];
$aop->rsaPrivateKey = $aliConfig['rsaPrivateKey'];
$aop->alipayrsaPublicKey = $aliConfig['alipayrsaPublicKey'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$request = new \AlipaySystemOauthTokenRequest ();
$request->setGrantType("authorization_code");
$request->setCode($code);
$result = $aop->execute ($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
if(isset($result->$responseNode->user_id)){
$user_id = $result->$responseNode->user_id;
$arr = [
'user_id' => $user_id
];
$res = $this->User->where('id',$id)->update($arr);
if (!$res){
return error_msg();
}else{
$this->SetRedis($id,'user_id',$user_id);
return success_msg();
}
} else {
return error_msg();
}
}
- 码字不易,求点赞
- 如果任何侵权行为请联系管理员删除
|