管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。+ t0 @. s! o: @. o% M7 c6 P
1.添加商品信息& c5 |% J- \; g. P
2.添加图片
- B- m5 q5 B7 @* i7 w3.查询所有产品
) J' j2 @8 L9 f- A% F4.查询某个具体产品信息
' V1 |' Y3 W% F( O% S8 a5.删除某个产品
7 G9 u4 ~4 S) `6.删除图片8 N; w& B" U- }2 V$ |
7.图像识别
" \0 F0 I/ I# n. C! y
2 C' Y2 t- ^' c2 w1 I图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
; n2 @3 w; r9 X6 U1 v3 {4 \0 u# u; U$ `7 W& U/ t3 H
PHP示例:
! C% M9 g2 K( p# Q- <!--?php& L, P) m5 k* ] s/ [/ i2 k: Z
- // +----------------------------------------------------------------------
g( { u, g+ f" k - // | JuhePHP [ NO ZUO NO DIE ]: i: K0 L9 u; ?1 {6 `$ |" e
- // +----------------------------------------------------------------------/ X _" g" \! r2 P& v
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
2 w( a( l, \/ D2 e% }3 i& v - // +----------------------------------------------------------------------3 P8 x2 Y% N$ F; d
- // | Author: Juhedata <info@juhe.cn-->
/ k# K5 h& C5 t8 w+ F+ b X4 Z - // +----------------------------------------------------------------------
; I' V# z: ~8 i, v, a -
8 x1 i, g) G! v; B7 X - //----------------------------------9 L' z0 r: D& ~1 w
- // 图像识别调用示例代码 - 聚合数据
8 B5 |+ V9 g8 \; \8 {) P - // 在线接口文档:http://www.juhe.cn/docs/117( r- Y9 Q- }! {9 [3 K
- //----------------------------------
6 h' V) o7 Q& _ - ( i! F m& J; {! [+ U
- header('Content-type:text/html;charset=utf-8');* d% p- {' u3 a' I! N
-
( M. C; O, t( n% l/ y - + z; ?, T' l; J
- //配置您申请的appkey
- S2 O5 Z+ c7 q v' f8 [9 ^ - $appkey = "*********************";
3 x3 I4 W, j( w - " m! d3 b9 v ?3 L* }
-
5 l) Z3 S" h: d! } -
- {7 `/ K8 L% k) @& O* x7 \/ { - : z0 X, k1 U% D* P/ O# W9 H0 t# `
- //************1.图像上传************. W; s( W# o' o, B% I6 W
- $url = "http://japi.juhe.cn/image_recognition/upload";
* C7 I. y q8 x7 g+ A0 S - $params = array(
+ G$ h, o$ I5 z, w+ { - "file" => "",//上传的单张图片; b1 F! |2 j8 H: H, q4 _1 r
- "key" => $appkey,//APP Key* J( z5 q% z- n( M
- "pname" => "",//包名
" H. H+ C9 ]* e7 \2 _5 _ - );7 Z' T U5 ]- c+ T; f. x: w
- $paramstring = http_build_query($params);! `0 [* Z% c( W/ h
- $content = juhecurl($url,$paramstring,1);
# k( }& C5 U4 D9 H - $result = json_decode($content,true);" | i) z r# u1 b+ e! W, [
- if($result){
) n1 W8 e& t( B - if($result['error_code']=='0'){4 b0 z( m% Y$ C2 @9 y
- print_r($result); O% k; x( _5 p3 H$ Y1 g
- }else{ J; `& U* W4 y0 ^
- echo $result['error_code'].":".$result['reason'];
# Q5 g, a% |, r - }
* A* J4 ]3 z! K - }else{- b: m3 P8 V2 u; ?) d
- echo "请求失败";
4 h, |0 W% p! e - }
. I( U. @6 }- p: S" d - //**************************************************
7 X: e0 g! u! l l - 1 J8 \6 ` R8 R2 j" Z
-
. V ^: x, O; E" | -
`$ b8 f1 e4 \5 E+ @+ I: u -
) R; @! R: Y. j6 z - //************2.查寻上传图像信息************9 X0 j4 k6 E" r2 z% G Q
- $url = "http://japi.juhe.cn/image_recognition/findAll";" R) {0 a. ^2 z' }" w4 m' A- r1 z- u
- $params = array(, h2 R8 K8 ^. }( Y* q/ j8 L' N
- "key" => $appkey,//APP Key
4 M, ]/ z8 Y8 i3 o* Q - );
' K) ?. g' c Q3 ` - $paramstring = http_build_query($params);* G- j: q. A9 ]. {: j1 M! z
- $content = juhecurl($url,$paramstring);
, V: Y+ ?0 \3 a5 ? - $result = json_decode($content,true);
, y+ [8 Y6 O" L5 S - if($result){
2 h# p0 y. R' c - if($result['error_code']=='0'){
6 E: L. d0 T1 } i1 T - print_r($result);* x5 D- c( m! u/ m7 k9 R5 \, K( l
- }else{# x5 T0 c# a6 L4 Q6 J
- echo $result['error_code'].":".$result['reason'];! c/ W0 T: \( l* d( F
- }/ F: p4 h. K+ z8 n! q# Q
- }else{
) ~% Q O0 ?- l - echo "请求失败";
5 |* D* E9 p' M! k$ a - }+ y* \* Q2 A! j
- //**************************************************0 t4 _! h( t* |! p
- % ~9 y* O, k8 v. S4 p
- : w: o( _' c. J: E
-
2 S2 R0 w" I7 R, |1 u - 5 ^# U/ n$ k% `' \* G- P: O
- //************3.删除图像信息************
d) y' h- \" Y+ } _ - $url = "http://japi.juhe.cn/image_recognition/delete";4 N% L! r# d7 ~; T4 P( q
- $params = array(
; u' Q5 Q+ m a! G- k2 h( o- s - "key" => $appkey,//APP Key1 K2 o% P& J3 w5 l6 q% B& h; d
- "imageId" => "",//图片ID
+ a& w+ l/ K) e9 k) j$ w# g - );
; O1 I) d" K5 K5 T5 Z - $paramstring = http_build_query($params);! N6 J v. m( k& }$ w8 N! n4 B+ c
- $content = juhecurl($url,$paramstring);
# s+ |: R4 [6 g# h# A, E$ e - $result = json_decode($content,true);
2 p; G- M s6 K5 ` P, o - if($result){; Q& h. }: ]* @
- if($result['error_code']=='0'){. w8 r9 E3 Z$ ~! M S
- print_r($result);5 i6 F' N, g7 h: I2 r8 f
- }else{; \* Y; c' U$ W a6 b3 [
- echo $result['error_code'].":".$result['reason'];
5 H5 y4 k6 C* ~0 E1 N - }
0 ?; k8 Y+ F2 B7 O# L( n& U - }else{
4 _: P% L: r8 Q - echo "请求失败";; E; a9 I$ E/ k" J9 |
- }
. ^0 Z9 q. T2 S+ x& o4 }: \ - //**************************************************
- Q2 y K) N$ y: { - # a% ]$ P% F/ b4 I( C- V
- : u6 m: c' B$ n
- " C4 n# t( {! j* j/ \8 g8 x
- + t1 a" c7 C3 u* e# i
- //************4.图像识别************8 b `2 Q' K% N6 Y+ p
- $url = "http://japi.juhe.cn/image_recognition/check";
3 k' _; j) D& y4 U - $params = array(* T S9 J+ @& f8 v$ y( c
- "file" => "",//上传的图片
" Y" q, _- q% b3 v - "key" => $appkey,//APP Key
* ?' W, F3 h, e" J9 B) m) F' U6 i - "pname" => "",//包名
1 G7 `! ~- P6 I9 V7 e - "device_name" => "",//设备名称(如android OS或iphone OS)7 j4 B$ h" p& C3 P s4 Z% D4 r
- "device_version" => "",//设备版本(如:4.0.3)
" {" h: t' c; i: n& K- A - "latitude" => "",//纬度: o* M; }( P; ^- Q l/ q
- "longitude" => "",//经度* \# N! X! |2 s9 w, ~, I7 @9 h
- "uuid" => "",//设备id
" C( y' y8 Q' d' t4 k - "zone" => "",//请求地区" J4 a1 z$ e' v
- );
3 z/ P. ^( [* P2 y# ? - $paramstring = http_build_query($params);4 q- y# g$ d4 D9 T1 V
- $content = juhecurl($url,$paramstring,1);1 I% k$ F. }& W
- $result = json_decode($content,true);. r% ?3 p3 T7 L- W9 y* i: `3 |
- if($result){6 ^2 u+ T+ [9 R; Q! r
- if($result['error_code']=='0'){" I8 L( C6 Y" h' D1 Z
- print_r($result);4 S+ Z# t/ m" K/ z: H
- }else{
9 T0 C9 s. X- H: J3 R - echo $result['error_code'].":".$result['reason'];+ o5 I* M7 |) U
- }
! y" ^1 W. K) j* h' F/ ? - }else{
7 v7 f% V% s2 ~# q- v - echo "请求失败";
/ j4 |$ d& c$ L& P7 Q - }* i) E: e+ Y0 U% x. j- A$ T
- //**************************************************
) g! v" H7 s \, a - $ w2 T9 K; D3 v! s9 e
- * M$ R6 j/ h& v
- / E# u7 d$ A+ F* t$ L6 U
- # W r' P) d' b* F6 E" m) n$ O
- 8 @3 Q: Q, E0 c3 T+ X) w% D0 _+ _
- /**
/ y* J) f! {* }- b! `' R( z9 l - * 请求接口返回内容8 ~$ G! ^; \% o/ j, H
- * @param string $url [请求的URL地址]
4 D, L5 o0 m. E) v9 _ - * @param string $params [请求的参数]# F, ~6 ~2 W$ R+ ^) g
- * @param int $ipost [是否采用POST形式], ^$ l, D4 H) U0 Y4 j/ @
- * @return string8 v( W b ~3 D+ I, `, M
- */6 d1 q) T6 ^ P) Y T
- function juhecurl($url,$params=false,$ispost=0){" t2 p3 u$ | Y& K7 |# e' _4 i
- $httpInfo = array();- Q+ c) Y* o; \# ?' u, k
- $ch = curl_init();
" X7 z2 [' {- `" ^( f' t - / v- O6 k+ i# O
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );, a3 k& s% w+ d
- curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );( J! J: m L3 u& c% O. G
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
- F3 u0 F2 M( |$ f6 L7 ~4 a - curl_setopt( $ch, CURLOPT_TIMEOUT , 60);) q/ I% I# b( o- C
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );3 ?6 g6 ], c- n% j
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
6 \0 V9 v4 x( l7 H! X+ @6 ] - if( $ispost )
2 g( j: `; m4 g, f, b - {
2 A/ u9 g: i1 H: Z - curl_setopt( $ch , CURLOPT_POST , true );
/ Y( L6 V8 |7 d3 @4 Y8 ^' _" N# l - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
! [: U7 W8 _+ D o y7 x& J0 y - curl_setopt( $ch , CURLOPT_URL , $url );$ L7 u: V6 B! _, ?# \* X/ M/ c
- }: N4 p, V! _# Q( W7 N# L, C" I
- else
+ V V0 a& C4 Z4 x) Q' n - {
& T' l% Q0 O+ V5 N - if($params){
7 }( h' f' ?) p5 N+ h6 y5 U2 ^ - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
1 l* c2 Q4 A' R, }) s - }else{
. ], N& H5 k2 }/ q, u+ x( @ - curl_setopt( $ch , CURLOPT_URL , $url);: f8 l7 u# C# R3 J. k$ N# J1 q. R
- }
* T4 t" B% N( ]# H% ^$ V' b& M - }- J U! g$ t. t+ v
- $response = curl_exec( $ch );4 N1 ]; t/ j* X+ e1 V# |
- if ($response === FALSE) {7 ^ N& D1 I. ^7 t) _6 A( [
- //echo "cURL Error: " . curl_error($ch);
" d2 }4 G0 w2 D, d2 j - return false;0 R& u( m! Q/ x. c1 D
- }
7 I* v, m& `7 n4 o( j# x1 V9 F - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
' d! i2 k* b k _- M9 U( S: m S - $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );3 A" H! r8 v+ T) c6 P$ T0 X. W% q: a
- curl_close( $ch );
4 `2 o( B1 y, u& f. [* | - return $response;# L/ R3 R2 E/ n: G+ G
- }
复制代码
$ ?2 @6 L0 l C
2 c5 E9 l y* Q4 }0 X |
|