request; $hash = $request->post('hash'); $memo = $request->post('memo'); if($hash && $memo){ Yii::$app->redis->hset('trade_hash_memo',$hash,$memo); return ['code' => 0,'data' => [], 'msg' => '本地备注添加成功']; }else{ return ['code' => 1,'data' => [],'msg' => '交易hash值或者本地备注不能为空']; } } /** * 查看本地备注 */ public function actionGetMemo() { $request = Yii::$app->request; $hash = $request->post('hash'); if($hash){ $memo = Yii::$app->redis->hget('trade_hash_memo',$hash); return ['code' => 0,'data' => $memo]; }else{ return ['code' => 1,'data' => [],'msg' => '交易hash值不能为空']; } } public function actionAddressIsExist() { $get = Yii::$app->request->get(); $to = $get['coin_address'] ?? ''; if(empty($to)){ return ['code' => -1, 'msg' => '参数不能为空']; } $coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one(); if(!$coinTokenTransfer){ return ['code' => 0, 'msg' => 'record does not exist']; } return ['code' => 1, 'msg' => 'record already exists']; } public function actionTokenTransfer() { $get = Yii::$app->request->get(); $to = $get['coin_address'] ?? ''; if(empty($to)){ return ['code' => -1, 'msg' => '参数不能为空']; } $coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one(); if($coinTokenTransfer){ return ['code' => -1, 'msg' => 'record already exists']; } $fee = 100000; $amount = 1 * 1e8; $note = '2050糖果'; $execer = 'user.p.youngplus.token'; $isToken = true; $tokenSymbol = 'YPLUS'; $service = new Chain33Service(); $createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer); if(0 != $createRawTransaction['code']){ $msg = $createRawTransaction['msg']; $code = -1; goto doEnd; } $txHex = $createRawTransaction['result']; $privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2'; $expire = '1m'; $signRawTx = $service->signRawTx($privkey, $txHex, $expire); if(0 != $signRawTx['code']){ $msg = $signRawTx['msg']; $code = -1; goto doEnd; } $sign_str = $signRawTx['result']; $result = $service->sendTransaction($sign_str); if(0 != $result['code']){ $msg = $result['msg']; $code = -1; goto doEnd; } $code = 1; $msg = $result['result']; doEnd : $coinTokenTransfer = new CoinTokenTransfer(); $coinTokenTransfer->coin_address = $to; $coinTokenTransfer->msg = $msg; $coinTokenTransfer->code = $code; $coinTokenTransfer->save(); return ['code' => $code, 'msg' => $msg]; } }